我迁移到Android工作室,在我尝试运行应用程序之前,一切似乎都很好。 它停留在Launcher活动中然后崩溃,打印:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoSuchMethodError: No direct method <init>(ILjava/lang/String;)V in class Lcom/google/android/gms/common/api/Status; or its super classes (declaration of 'com.google.android.gms.common.api.Status' appears in /data/data/com.MY PACKAGE/files/instant-run/dex/slice-google-play-........b-classes.dex)
at com.google.android.gms.measurement.zza.<init>(Unknown Source)
at com.google.android.gms.measurement.zza.zzaR(Unknown Source)
at com.google.android.gms.measurement.internal.zzn.zziJ(Unknown Source)
at com.google.android.gms.measurement.internal.zzz.zza(Unknown Source)
at com.google.android.gms.measurement.internal.zzw.<init>(Unknown Source)
at com.google.android.gms.measurement.internal.zzaa.zzDj(Unknown Source)
at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source)
at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1728)
at android.app.ActivityThread.installProvider(ActivityThread.java:5534)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5105)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5045)
at android.app.ActivityThread.access$1600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1459)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
答案 0 :(得分:10)
对我而言,问题在于,我的游戏服务依赖项的不同版本有所不同,例如
dependencies {
compile 'com.google.android.gms:play-services-gcm:8.4.0' /different version
compile 'com.google.android.gms:play-services-maps:9.0.2'
compile 'com.google.android.gms:play-services-location:9.0.2'
}
应改为
dependencies {
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile 'com.google.android.gms:play-services-maps:9.0.2'
compile 'com.google.android.gms:play-services-location:9.0.2'
}
我希望它适合你或遇到同样问题的人。
答案 1 :(得分:1)
将此行添加到您的清单文件
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
并将此添加到您的gradle
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
第二个解决方案:
将此添加到您的启动器活动的onCreate()方法
public void onCreate(Bundle arguments) {
Context context = this.getInstrumentation().getTargetContext().getApplicationContext();
MultiDex.install(context );
super.onCreate(arguments);
...
}
或强>
需要在扩展Application的类中添加它:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
了解更多细节: link 1,link 2,link 3,link 4
希望它有效..
答案 2 :(得分:0)
对我来说,我遇到了丢失方法的类似崩溃,因为我必须在我的build.gradle
文件中更新最近添加的库版本。
答案 3 :(得分:-1)
添加Google Play服务依赖项
dependencies {
compile 'com.google.android.gms:play-services:8.4.0'//update with latest version
}
或者,
compile 'com.google.android.gms:play-services-gcm:8.4.0'//update with latest version
清理项目&amp;重建