简体   繁体   English

java.lang.NoClassDefFoundError: com.google.android.gms.R$字符串

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

I am having a little trouble with the complier, Same code I use on Nexus 5, no error.我在编译器上遇到了一些麻烦,我在 Nexus 5 上使用的代码相同,没有错误。 as Soon as I use it in Tablet, it crash right away and the error said只要我在平板电脑上使用它,它就会立即崩溃并显示错误

java.lang.NoClassDefFoundError: com.google.android.gms.R$string with brunch of unknown source... java.lang.NoClassDefFoundError: com.google.android.gms.R$string with brunch of unknown source...

and if i remove如果我删除

multiDexEnabled true 

and remove并删除

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

then it works on both, does anybody know the reason why?然后它对两者都有效,有人知道为什么吗? Below is my build.grade下面是我的 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 is the manifest.xml吹的是manifest.xml

  <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.name" >

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission
    android:name="com.google.android.c2dm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<application
    android:name=".utility.Apps"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:largeHeap="true"
    android:theme="@style/AppTheme" >
    <receiver
        android:name=".gcm.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </receiver>

    <service android:name=".gcm.GcmIntentService" />

    <activity android:name=".SplashActivity"
              android:theme="@style/AppTheme.NoActionBar" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    and then a lot of activities

I look into my code many time, and I look at each library I am using and I was able to fix it.我多次查看我的代码,查看我正在使用的每个库,我能够修复它。

First, like @BrainMiz said mutiDexEnabled should set it off.首先,就像@BrainMiz 所说的 mutiDexEnabled 应该将其关闭。 I just comment it instead of set it as false.我只是评论它而不是将其设置为 false。

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

Second, it is the dependencies.其次,它是依赖关系。 Since I don't have any jar in my libs folder I remove因为我的 libs 文件夹中没有任何 jar,所以我删除了

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

also remove all not being used gms library, only add the one that being used.还删除所有未使用的 gms 库,仅添加正在使用的库。 I have to give some credits to @Radix because I did found some error in my code regarding to the code that where I check if the device has google play store.我必须感谢@Radix,因为我确实在我的代码中发现了一些关于我检查设备是否有谷歌游戏商店的代码的错误。

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'
}

I believe you should try turning multiDexEnabled false and get rid of the compile 'com.google.android.gms:play-services-gcm:8.4.0'.我相信您应该尝试将 multiDexEnabled 设为 false 并摆脱编译“com.google.android.gms:play-services-gcm:8.4.0”。 You have two play-services which forces you to turn multiDexEnabled to true您有两个播放服务,它们迫使您将 multiDexEnabled 设置为 true

Change this line改变这一行

<uses-permission
android:name="com.google.android.c2dm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

with this有了这个

<permission android:name="<your-package-name>.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="<your-package-name>.permission.C2D_MESSAGE" />

Also i see a lot of anomaly in your manifest with respect to how you have declared GCM.此外,我在您的清单中看到很多关于您如何声明 GCM 的异常情况。 Have a look at the technical docs.看看技术文档。

Got the same problem.. just clean the project, then make it and finally run it遇到同样的问题..只是清理项目,然后制作它并最后运行它

In my case, I changed the theme of my app in the AndroidManifest.xml file and cleared out my styles.xml file (because I'm a noob and hoped to just use an out-of-the-box android theme).在我的例子中,我在 AndroidManifest.xml 文件中更改了我的应用程序的主题并清除了我的 styles.xml 文件(因为我是一个菜鸟,希望只使用开箱即用的 android 主题)。 After launching the app, I assume there were zombie references to the old theme that caused the error because, after reverting my changes, the error disappeared.启动该应用程序后,我假设存在对导致错误的旧主题的僵尸引用,因为在恢复我的更改后,错误消失了。

I did remove我确实删除了

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

and sync project.和同步项目。 After added this line and synced again.添加此行并再次同步后。 Next, cleaned project to remove old dex files (may cause problem with dex archives merging), and it helped.接下来,清理项目以删除旧的 dex 文件(可能会导致 dex 存档合并出现问题),这很有帮助。

I'm working on Xamarin android. 我正在使用Xamarin android。 Just Clean the solution and try to rebuild the project, then just run your application. 只需清理解决方案并尝试重建项目,然后运行您的应用程序即可。 This worked for me. 这对我有用。

I had the same issue我遇到过同样的问题

Had in gradle.build dependencies:在 gradle.build 依赖项中:

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

And in AndroidManifest.xml:在 AndroidManifest.xml 中:

<application
        ...
        android:name="android.support.multidex.MultiDexApplication">

Having same issue and was stuck for a whole day.遇到同样的问题,被困了一整天。 Finally got solution.终于得到解决方案。

Add in your app level gradle.build :添加到您的应用级别gradle.build

repositories {
  jcenter()
}

dependencies {
  compile 'com.google.android:multidex:0.1'
}

Then override attachBaseContext in your Application class like below:然后在您的Application类中覆盖attachBaseContext ,如下所示:

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

And don't forgot to enable mutlidex support as below:并且不要忘记启用 mutlidex 支持,如下所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android错误:java.lang.NoClassDefFoundError:com.google.android.gms.R $ string - Android error: java.lang.NoClassDefFoundError: com.google.android.gms.R$string Android Google Maps v2:java.lang.NoClassDefFoundError:com.google.android.gms.R $ styleable - Android Google Maps v2: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable Android错误:SDK23 v SDK19-java.lang.NoClassDefFoundError:com.google.android.gms.R $ string - Android Error: SDK23 v SDK19 - java.lang.NoClassDefFoundError: com.google.android.gms.R$string 运行时错误:java.lang.NoClassDefFoundError:com.google.android.gms.R $ styleable - Run Time Error : java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable java.lang.noclassdeffounderror:com.google.android.gms.R $ styleable没什么帮助我的 - java.lang.noclassdeffounderror: com.google.android.gms.R$styleable nothing helped me java.lang.NoSuchFieldError:com.google.android.gms.R $ string.location_client_powered_by_google - java.lang.NoSuchFieldError: com.google.android.gms.R$string.location_client_powered_by_google java.lang.NoClassDefFoundError:com.google.android.gms.gcm.GoogleCloudMessaging使用java.lang.NoClassDefFoundError: - java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging using java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError:解析失败:Lcom/google/android/gms/common/R$string; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string; Google AdMob java.lang.NoClassDefFoundError:com.google.android.gms.ads.AdView - Google AdMob java.lang.NoClassDefFoundError: com.google.android.gms.ads.AdView Android)java.lang.NoClassDefFoundError:com.google.android.gms.internal.zzno - Android ) java.lang.NoClassDefFoundError: com.google.android.gms.internal.zzno
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM