0

次のコードを使用して、OLA アプリのような GPS をオンにしました。以下のコードは、Play Services 8.4.0 を使用して Android Studio で正常に実行されます。しかし、ADT 23 を使用して Eclipse でこれを実行したいと考えています。

SDKで最新のGoogleプレイサービスを検索しました。利用できません。そして、ついに最新の aar8.4.0 ファイルを見つけました。AARを通常のEclipseライブラリプロジェクトに変換し、Eclipseにインポートして更新し、ライブラリとしてメインプロジェクトに追加した後。

まだこのエラーが発生しています.次の API はメイン ソース コード アクティビティでサポートされていません。

com.google.android.gms.common.ConnectionResult をインポートします。com.google.android.gms.common.api.GoogleApiClient をインポートします。com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks をインポートします。com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener をインポートします。com.google.android.gms.location.LocationRequest をインポートします。

私のコード:

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); 設定要求(); } //------------------------------------------------------------- --------------------------------------

public void settingsrequest()
{
    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(30 * 1000);
    locationRequest.setFastestInterval(5 * 1000);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);

    builder.setAlwaysShow(true); //this is the key ingredient

    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(LocationSettingsResult result) {
            final Status status = result.getStatus();
            final LocationSettingsStates state = result.getLocationSettingsStates();
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    // All location settings are satisfied. The client can initialize location
                    // requests here.
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    // Location settings are not satisfied. But could be fixed by showing the user
                    // a dialog.
                    try {
                        // Show the dialog by calling startResolutionForResult(),
                        // and check the result in onActivityResult().
                        status.startResolutionForResult(this, REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException e) {
                        // Ignore the error.
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    // Location settings are not satisfied. However, we have no way to fix the
                    // settings so we won't show the dialog.
                    break;
            }
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {

    // Check for the integer request code originally supplied to startResolutionForResult().
        case REQUEST_CHECK_SETTINGS:

            switch (resultCode) {

            case Activity.RESULT_OK:

                //startLocationUpdates();

                GetLocation() ;

                break;

            case Activity.RESULT_CANCELED:

            settingsrequest();//keep asking if imp or do whatever

            break;
            }

            break;
    }
}

//------------------------------------------------ ----------------------

注: このコードは、Android Studio 2.1 で完全に動作します。設定ページに移動せずに、ダイアログ「はい/いいえ」自体でGPSを直接オンにするような出力を見ました。

しかし、Eclipseでも同じ出力が必要です。私も問題を発見しました、どこですか?問題はGoogle Playサービスのみです。現在、Google APIはAAR形式のみのライブラリを提供しています(スタジオは受け入れられます)。

解決策を得るのを手伝ってください。

4

1 に答える 1

0

グラドルビルドファイル

Android プロジェクトの build.gradle の末尾に次を追加します。

task copyJarDependencies(type: Copy) {
    description = 'Used for Eclipse. Copies all dependencies to the libs directory. If there are any AAR files it will extract the classes.jar and rename it the same as the AAR file but with a .jar on the end.'
    libDir = new File(project.projectDir, '/libs')
    println libDir
    println 'Adding dependencies from compile configuration'
    configurations.compile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
    println 'Adding dependencies from releaseCompile configuration'
    configurations.releaseCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
    println 'Adding dependencies from debugCompile configuration'
    configurations.debugCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
    println 'Adding dependencies from instrumentTestCompile configuration'
    configurations.instrumentTestCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
    println 'Extracting dependencies from compile configuration'
    configurations.compile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
    println 'Extracting dependencies from releaseCompile configuration'
    configurations.releaseCompile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
    println 'Extracting dependencies from debugCompile configuration'
    configurations.debugCompile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
    println 'Extracting AAR dependencies from instrumentTestCompile configuration'
    configurations.instrumentTestCompile.filter {it.name.endsWith 'aar'}.each { File file -> moveAndRenameAar(file) }
}

void moveJarIntoLibs(File file){
    println 'Added jar ' + file
        copy{
            from file
            into 'libs'
        }
}

void moveAndRenameAar(File file){
    println 'Added aar ' + file
    def baseFilename = file.name.lastIndexOf('.').with {it != -1 ? file.name[0..<it] : file.name}

    // directory excluding the classes.jar
    copy{
        from zipTree(file)
        exclude 'classes.jar'
        into 'libs/'+baseFilename
    }

    // Copies the classes.jar into the libs directory of the expoded AAR.
    // In Eclipse you can then import this exploded ar as an Android project
    // and then reference not only the classes but also the android resources :D 
    copy{
        from zipTree(file)
        include 'classes.jar'
        into 'libs/' + baseFilename +'/libs'
        rename { String fileName ->
            fileName.replace('classes.jar', baseFilename + '.jar')
        }
    }
}

GRADLE を使用したビルド

gradle clean build を実行します (または Eclipse 内で build.gradle Rus As -> Gradle build を右クリックします)。

すべての依存関係と展開された AAR が libs ディレクトリにあります。Eclipse に必要なのはこれだけです。

日食でのインポート

ここからが本当のメリットの始まりです。上記の gradle ステップから libs ディレクトリを生成すると、そこにもフォルダーがあることに気付くでしょう。これらの新しいフォルダーは、build.gradle ファイルから展開された AAR 依存関係です。

優れた点は、既存の Android プロジェクトを Eclipse にインポートすると、展開された AAR フォルダーもインポート可能なプロジェクトとして検出されることです。

  1. プロジェクトの libs ディレクトリの下にあるこれらのフォルダーをインポートします。「ビルド」フォルダーはインポートしないでください。それらは Gradle によって生成されます。

  2. 追加したすべての AAR プロジェクトで Project -> Clean を実行してください。ワークスペースで、AAR 展開された各プロジェクトの project.properties に次のものが含まれていることを確認します。

target=android- android.library=true 3. これで、メインの Android プロジェクトで、ADT を使用してライブラリ参照を追加するか、project.properties ファイルを編集して追加することができます。

android.libraries.reference.1=libs/someExplodedAAR/
  1. これで、メインの Android プロジェクトを右クリックして、[Run as] -> [Android Application] を選択できます。

情報元:

http://www.nodeclipse.org/projects/gradle/android/aar-for-Eclipse

于 2016-07-27T10:04:28.470 に答える