Android需要将ear play服务8.4.0导入eclipse

时间:2016-07-27 09:57:59

标签: android android-studio google-play-services arr google-location-services

我使用以下代码来启用像OLA app这样的gps。以下代码在Android Studio中成功运行,播放服务为8.4.0。 但是,我想在Eclipse中使用ADT 23运行它。

我在sdk的最新google playservices中搜索过。它不可用。最后,我找到了最新的aar8.4.0文件。在我将AAR转换为普通的Eclipse Library项目并导入到eclipse并刷新并作为库添加到我的主项目之后。

仍然收到此错误。以下主要源代码活动中不支持API。

导入com.google.android.gms.common.ConnectionResult; 导入com.google.android.gms.common.api.GoogleApiClient; 导入com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.LocationRequest;

我的代码:

@覆盖 public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); 的setContentView(R.layout.main); settingsrequest(); } // ------------------------------------------------ ------------------------------------

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服务。现在只提供AAR格式的Google API(工作室可接受)。

请帮助解决问题。

1 个答案:

答案 0 :(得分:0)

GRADLE BUILD FILE

将以下内容添加到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 - &gt; Gradle build)

您应该在libs目录中找到所有依赖项和爆炸的AAR。这是Eclipse应该需要的全部内容。

进入ECLIPSE

现在这是真正的利益开始的地方。从上面的gradle步骤生成libs目录后,您会发现其中也有文件夹。这些新文件夹是build.gradle文件中爆炸的AAR依赖项。

现在很酷的部分是,当你将现有的Android项目导入Eclipse时,它也会将爆炸的AAR文件夹检测为它可以导入的项目!

  1. 将这些文件夹导入项目的libs目录下,不要导入任何&#39; build&#39;文件夹,由Gradle

  2. 生成
  3. 确保您执行项目 - &gt;清理您已添加的所有AAR项目。在工作区中,检查每个AAR爆炸项目在project.properties中是否包含以下内容:

  4. 目标= android- android.library =真 3.现在在您的主要Android项目中,您可以使用ADT添加库引用,或者您只需编辑project.properties文件并添加

    android.libraries.reference.1=libs/someExplodedAAR/
    
    1. 现在您可以右键单击主Android项目并运行为 - &gt; Android应用程序。
    2. 来自:

      的信息

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

相关问题