我将我的应用程序与 google 播放服务集成,但在 5.X 之前的旧版本中,它在将 google 播放服务更新到 8.4.0 后崩溃
i integrated my app with google play services but in old versions before 5.X it crashes after updating google play service to 8.4.0
该应用程序在 5.X 之后的任何版本中都能成功启动,但在旧版本中 4.X 它崩溃并给我这个错误:
java.lang.NoClassDefFoundError: com.google.android.gms.R$string
这是builde.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.appsinnovate.hanorder"
// manifestPlaceholders =
[manifestApplicationId:"${applicationId}"]
manifestPlaceholders = [manifestApplicationId :
"${applicationId}",
onesignal_app_id
: "xxxxxxxxxxxx",
onesignal_google_project_number:"xxxxxxxxx"]
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
productFlavors {
}
useLibrary 'org.apache.http.legacy'
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':facebook')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:palette-v7:23.1.1'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.onesignal:OneSignal:1.+@aar'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
build.gradle(申请)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
}
}
allprojects {
repositories {
jcenter()
}
}
如果您没有将 google 播放服务库正确添加到您的项目中,您将会得到这个。请务必仔细按照 https://developers.google.com/android/guides/setup to add the library to your project. Then make sure you have all of your build tools and google repository packages up to date, as outline in my answer here:
中的说明进行操作
更新所有这些后,它应该可以工作。我还注意到您的 google 播放包看起来已经过时了。你的版本是 2.0.0。当前版本应为 8.4.0
您 gradle 中的行应显示为 compile 'com.google.android.gms:play-services:8.4.0'
另外,您的项目 gradle 文件中似乎有这个。它应该放在您的 MODULE gradle 文件中。
更新
您应该将您的 gradle 版本更改为 classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
我在最初通读时错过了这个,但这应该可以解决您的问题。
我通过删除
解决了这个问题
compile 'com.google.android.gms:play-services:8.4.0'
因为大小超过65K需要使用multiDexing
所以我从 builde.gradle
中删除了
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
......
multiDexEnabled true
......
compile 'com.android.support:multidex:1.0.0'
并且我使用了我需要的库
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
该应用程序在 5.X 之后的任何版本中都能成功启动,但在旧版本中 4.X 它崩溃并给我这个错误:
java.lang.NoClassDefFoundError: com.google.android.gms.R$string
这是builde.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.appsinnovate.hanorder"
// manifestPlaceholders =
[manifestApplicationId:"${applicationId}"]
manifestPlaceholders = [manifestApplicationId :
"${applicationId}",
onesignal_app_id
: "xxxxxxxxxxxx",
onesignal_google_project_number:"xxxxxxxxx"]
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
productFlavors {
}
useLibrary 'org.apache.http.legacy'
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':facebook')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:palette-v7:23.1.1'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.onesignal:OneSignal:1.+@aar'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
build.gradle(申请)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
}
}
allprojects {
repositories {
jcenter()
}
}
如果您没有将 google 播放服务库正确添加到您的项目中,您将会得到这个。请务必仔细按照 https://developers.google.com/android/guides/setup to add the library to your project. Then make sure you have all of your build tools and google repository packages up to date, as outline in my answer here:
更新所有这些后,它应该可以工作。我还注意到您的 google 播放包看起来已经过时了。你的版本是 2.0.0。当前版本应为 8.4.0
您 gradle 中的行应显示为 compile 'com.google.android.gms:play-services:8.4.0'
另外,您的项目 gradle 文件中似乎有这个。它应该放在您的 MODULE gradle 文件中。
更新
您应该将您的 gradle 版本更改为 classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
我在最初通读时错过了这个,但这应该可以解决您的问题。
我通过删除
解决了这个问题 compile 'com.google.android.gms:play-services:8.4.0'
因为大小超过65K需要使用multiDexing
所以我从 builde.gradle
中删除了 dexOptions {
incremental true
javaMaxHeapSize "4g"
}
......
multiDexEnabled true
......
compile 'com.android.support:multidex:1.0.0'
并且我使用了我需要的库
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'