java.lang.NoClassDefFoundError:com.google.android.gms.R $ string

我对编译器有点麻烦,我在Nexus 5上使用相同的代码,没有错误。 因为我在平板电脑中使用它,它立即崩溃,错误说

java.lang.NoClassDefFoundError:com.google.android.gms.R $字符串,含有未知来源的早午餐……

如果我删除

multiDexEnabled true 

并删除

  compile 'org.twitter4j:twitter4j-core:4.0.2' 

然后它适用于两者,有人知道原因吗? 下面是我的build.grade

 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.package.name" minSdkVersion 16 targetSdkVersion 23 versionCode 1 versionName "1.0" multiDexEnabled true } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'org.twitter4j:twitter4j-core:4.0.2' compile 'com.android.support:multidex:1.0.1' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.google.android.gms:play-services:8.4.0' compile 'com.android.support:design:23.1.1' compile 'com.squareup.okhttp:okhttp:2.5.0' compile 'com.android.support:support-v4:23.1.1' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.isseiaoki:simplecropview:1.0.8' compile 'com.qozix:tileview:2.0.7' compile 'com.android.support:cardview-v7:23.1.1' compile 'com.google.android.gms:play-services-gcm:8.4.0' } 

Blow是manifest.xml

                          and then a lot of activities 

我多次查看我的代码,然后查看我正在使用的每个库,我能够修复它。

首先,像@BrainMiz一样说mutiDexEnabled应该将其关闭。 我只是评论它而不是将其设置为false。

 defaultConfig { applicationId "com.package.name" minSdkVersion 16 targetSdkVersion 23 versionCode 1 versionName "1.0" //multiDexEnabled true } 

其次,它是依赖关系。 因为我的libs文件夹中没有任何jar,所以我删除了

  compile fileTree(dir: 'libs', include: ['*.jar']) 

还删除所有未使用的gms库,只添加正在使用的那个。 我必须给@Radix一些学分,因为我在代码中发现了一些关于代码的错误,我检查设备是否有google play store。

 dependencies { //compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'org.twitter4j:twitter4j-core:4.0.2' compile 'com.android.support:multidex:1.0.1' compile 'com.android.support:appcompat-v7:23.1.1' //compile 'com.google.android.gms:play-services:8.4.0' compile 'com.android.support:design:23.1.1' compile 'com.squareup.okhttp:okhttp:2.5.0' //compile 'com.android.support:support-v4:23.1.1' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.isseiaoki:simplecropview:1.0.8' compile 'com.qozix:tileview:2.0.7' compile 'com.android.support:cardview-v7:23.1.1' compile 'com.google.android.gms:play-services-gcm:8.4.0' } 

改变这一行

  

有了这个

   

此外,我在你的清单中看到了很多关于你如何宣布GCM的exception现象。 看一下技术文档。

我相信你应该尝试将multiDexEnabled变为false并摆脱编译’com.google.android.gms:play-services-gcm:8.4.0’。 你有两个播放服务强制你将multiDexEnabled变为true

得到了同样的问题..只需清理项目,然后制作它,最后运行它

在我的例子中,我在AndroidManifest.xml文件中更改了我的应用程序的主题,并清除了我的styles.xml文件(因为我是一个菜鸟,希望只使用一个开箱即用的android主题)。 启动应用程序后,我假设有旧主题的僵尸引用导致错误,因为在恢复我的更改后,错误消失了。

我确实删除了

  compile 'com.android.support:multidex:1.0.1' 

和同步项目。 添加此行后再次同步。 接下来,清理项目以删除旧的dex文件(可能会导致dex存档合并问题),并且它有所帮助。

我遇到过同样的问题

在gradle.build依赖项中:

 compile 'com.android.support:multidex:1.0.0' 

在AndroidManifest.xml中:

  

有同样的问题,被困了一整天。 终于有了解决方案

在您的应用级别添加gradle.build

 repositories { jcenter() } dependencies { compile 'com.google.android:multidex:0.1' } 

然后在Application类中重写attachBaseContext ,如下所示:

 @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } 

并且不要忘记启用mutlidex支持 ,如下所示:

 android { ... defaultConfig { ... multiDexEnabled true } }