我的代码有问题。
到目前为止,我使用Eclipse,但现在我使用的是Android Studio。
(在Eclipse中) 我有一个名为 MoST 的图书馆计划,需要 google_play_service_r16 图书馆计划。要在Android Studio中导入此项目:
1)在Eclipse中,我将google_play_service_r16添加到MoST。
2)将文件导出为 build.gradle 。
3)最后我导入了build.gradle,然后在Android Studio中创建 MoST.aar 。
在Android Studio中,我创建了一个使用MoST模块的新项目。当我尝试运行我的新应用程序时,我有这个错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.unipa.uniar, PID: 23978
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/GooglePlayServicesClient$ConnectionCallbacks;
at org.most.MoSTApplication.onCreate(MoSTApplication.java:66)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1032)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5881)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1718)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.GooglePlayServicesClient$ConnectionCallbacks" on path: DexPathList[[zip file "/data/app/com.unipa.uniar-2/base.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.unipa.uniar-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.unipa.uniar-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at org.most.MoSTApplication.onCreate(MoSTApplication.java:66)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1032)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5881)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1718)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
我的app模块build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.unipa.uniar"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':most')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-base:10.2.1'
testCompile 'junit:junit:4.12'
compile files('libs/weka-3.6.6-android.jar')
compile files('libs/org.apache.commons.io.jar')
compile files('libs/bcprov-jdk15on-155.jar')
compile files('libs/apache-httpcomponents-httpclient.jar')
compile files('libs/httpcore-4.4.6.jar')
}
(大多数模块)AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.most"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission for activity recognition -->
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<application
android:name="org.most.MoSTApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="MoSTService"
android:enabled="true" >
</service>
</application>
</manifest>
错误说 大部分都没有找到课程&#34; com.google.android.gms.common.GooglePlayServicesClient $ ConnectionCallbacks&#34;
我该如何解决这个问题?
答案 0 :(得分:0)
<强>解强>
GooglePlayServicesClient类已弃用一段时间了。最新版本的Google Play服务(如10.2.1)可能会产生各种问题。在我的情况下,我不能使用较新的版本,因为我无法直接编辑库。要解决这个问题已经包含谷歌播放服务版本4.3.23,其中包括GooglePlayServiceClient,我解决了这个问题。 AndroidManifest.xml(最终):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.unipa.uniar">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Permission for Network -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- Permission for activity recognition -->
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light"
tools:replace="android:allowBackup,android:icon,android:theme">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".Welcome"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity" />
<activity android:name=".TrainingSet" />
<activity android:name=".Testing"></activity>
</application>
</manifest>
这是gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.unipa.uniar"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':most')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:4.3.23'
testCompile 'junit:junit:4.12'
compile files('libs/weka-3.6.6-android.jar')
compile files('libs/org.apache.commons.io.jar')
compile files('libs/bcprov-jdk15on-155.jar')
compile files('libs/apache-httpcomponents-httpclient.jar')
compile files('libs/httpcore-4.4.6.jar')
}