【问题标题】:java.lang.NoClassDefFoundError: com.google.android.gms.R$stringjava.lang.NoClassDefFoundError: com.google.android.gms.R$string
【发布时间】:2015-12-21 20:09:25
【问题描述】:

编译器有点麻烦, 我在 Nexus 5 上使用的代码相同,没有错误。 一旦我在平板电脑中使用它,它就立即崩溃并显示错误

java.lang.NoClassDefFoundError: com.google.android.gms.R$string 与未知来源的早午餐...

如果我删除了

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

  <?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

【问题讨论】:

  • 保持一切不变并将 minifyEnabled 设为 false
  • @Radix 我只是将 minifyEnabled 设置为 false。同样的错误。一旦我排除 twitter4J jar 就可以了。但我需要 twitter 4j .....
  • 您可以发布您的堆栈跟踪和清单文件吗?

标签: java android android-manifest twitter4j


【解决方案1】:

我相信您应该尝试将 multiDexEnabled 设为 false 并摆脱 compile 'com.google.android.gms:play-services-gcm:8.4.0' 。您有两个播放服务迫使您将 multiDexEnabled 设置为 true

【讨论】:

  • 是的,你是对的,我这样做是因为我从其他帖子中看到了答案。我只是想办法解决它。我将发布答案。
【解决方案2】:

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

首先,就像@BrainMiz 所说的 mutiDexEnabled 应该将其关闭。我只是评论它而不是将其设置为假。

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 一些功劳,因为我确实在我的代码中发现了一些关于我检查设备是否有谷歌播放商店的代码的错误。

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

      我遇到了同样的问题

      在 gradle.build 中有依赖:

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

      在 AndroidManifest.xml 中:

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

      【讨论】:

        【解决方案5】:

        遇到同样的问题,卡了一整天。终于找到解决办法了。

        在您的应用级别添加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
            }
        }
        

        【讨论】:

          【解决方案6】:

          改变这一行

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

          有了这个

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

          另外,我在您的清单中看到了很多关于您如何声明 GCM 的异常情况。看看technical docs.

          【讨论】:

            【解决方案7】:

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

            【讨论】:

              【解决方案8】:

              我确实删除了

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

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

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2013-03-31
                • 2016-04-22
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多