2015-12-21 20 views
3

我对编译器有点麻烦, 我在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' 

} 

吹是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 
+0

保留所有内容,并将minifyEnabled设为false –

+0

@Radix我只是将minifyEnabled设置为false。 同样的错误。只要我排除twitter4J罐,那么它很好。但我需要twitter 4j tho ..... –

+0

你可以发布你的stacktrace和你的清单文件吗? –

回答

1

我看了很多次我的代码,我看着我使用的每个库,我能够修复它。

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

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

其次,它是依赖关系。 因为我没有在我的库的任何文件夹罐子我删除

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

改变这一行

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

0

我相信你应该尝试将multiDexEnabled设置为false,并去掉编译'com.google.android.gms:play-services-gcm:8.4.0'。你有两个播放服务,它迫使你把multiDexEnabled变成true

+0

是的,你是对的,我这样做是因为我看到了其他职位的答案。我只是想出了解决这个问题的方法。我将发布答案。 –

0

我有同样的问题

曾在gradle.build依赖关系:

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

而且在AndroidManifest.xml:

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

有同样的问题,被卡住一整天。终于有了解决办法

添加在你的应用水平gradle.build

repositories { 
    jcenter() 
} 

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

然后覆盖attachBaseContext应用类象下面这样:

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

而且不要忘了启用mutlidex支持如下:

android { 
    ... 
    defaultConfig { 
     ... 
     multiDexEnabled true 
    } 
} 
相关问题