minify = true 时安装应用程序时出错
Error on installing the app when minify = true
我正在开发一个我正在使用 urbanairship 的应用程序,该应用程序构建正确并且安装也正确但是当它被初始化时某些东西会使它崩溃但只有当 minify 为真时,如果它为假它 运行 非常好。
错误:
我已经尝试实施 multidex 但没有成功
错误:
Process: qa.vodafone.myvodafone.prd, PID: 24925
java.lang.NoSuchMethodError: No virtual method object()Lj/c/f; in class Lj/c/f; or its super classes (declaration of 'j.c.f' appears in
base.apk)
at c.n.k.d.a(Unknown Source:0)
at c.n.k.d.toString(Unknown Source:5)
at com.urbanairship.job.AirshipService.a(:2)
at c.n.i.h.a(:9)
at c.n.s.c.a(:2)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
apply plugin: "com.soasta.mpulse.android"
android {
signingConfigs {
}
compileSdkVersion 28
defaultConfig {
applicationId ""
minSdkVersion 21
targetSdkVersion 28
versionCode 224
versionName "10.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debuggable = false
jniDebuggable = false
renderscriptDebuggable = false
signingConfig signingConfigs.releaseTest
}
}
flavorDimensions "default"
productFlavors {
}
def name = "mva"
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${name}_${variant.name}_${versionName}.apk"
}
}
lintOptions {
disable 'TypographyFractions', 'TypographyQuotes'
enable 'RtlHardcoded', 'RtlCompat', 'RtlEnabled'
check 'NewApi', 'InlinedApi'
quiet false
abortOnError true
ignoreWarnings true
checkAllWarnings true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.core:core-ktx:1.2.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "com.airbnb.android:lottie:$lottie_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
testImplementation 'org.mockito:mockito-core:1.10.19'
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
implementation "android.arch.lifecycle:livedata:1.1.1"
implementation "com.squareup.moshi:moshi-kotlin:1.8.0"
implementation "com.squareup.moshi:moshi-adapters:1.5.0"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1"
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.1.0'
implementation "com.google.android.gms:play-services-maps:${gmsServicesVersion}"
implementation "com.google.android.gms:play-services-location:${gmsServicesVersion}"
implementation "com.google.android.gms:play-services-analytics:${gmsServicesVersion}"
implementation 'com.google.android.libraries.places:places:2.0.0'
implementation 'com.google.maps:google-maps-services:0.2.4'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.biometric:biometric:1.0.0-alpha04'
implementation 'com.gauravbhola.ripplepulsebackground:library:1.0.0'
implementation 'me.everything:overscroll-decor-android:1.0.4'
// Airship SDK - FCM
implementation 'com.urbanairship.android:urbanairship-fcm:10.0.2'
// Firebase
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-iid:19.0.1'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
//Adobe Analytics
implementation 'com.adobe.mobile:adobeMobileLibrary:4.17.9'
//implementation 'com.adobe.marketing.mobile:sdk-core:1.4.0'
//implementation 'com.adobe.marketing.mobile:target:1.1.1'
// Tealium
implementation 'com.tealium:library:5.5.4'
implementation 'com.tealium:lifecycle:1.1.2'
implementation('com.soasta.mpulse:mpulse-android:2.6.3') {
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: "com.android.tools.build", module: "gradle"
}
//Zopim Chat
implementation group: 'com.zopim.android', name: 'sdk', version: '1.4.1'
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
implementation ('com.crashlytienter code herecs.sdk.android:crashlytics:2.10.1@aar') {
transitive = true
}
}
mpulseAndroid {
exclude ~/.*classes.jar/
}
根据我的了解,这是您在首次启用缩小时 运行 遇到的常见问题。缩小器(ProGuard 或 R8)会删除代码中未直接引用的任何方法,作为缩小 APK 工作的一部分。这个功能非常有用——当我第一次使用它时,它从我的 APK 中删除了很多未使用的方法,以至于我不再需要 MultiDex。
但这会导致问题 - 有时有些方法可能永远不会在您的代码中直接调用,而是通过反射或在生成的代码中调用,例如使用 Otto/EventBus 时的 @Subscribe
方法和 @OnClick
使用 ButterKnife 时的方法。缩小器也错误地删除了这些方法,你只有在构建和 运行ning 之后得到 NoSuchMethodError
时才会发现。更糟糕的是,您不知道哪个方法被错误地删除了,因为方法名称被 j.c.f
.
之类的名称混淆了
我是这样解决的。首先,禁用混淆,这样你就可以看到哪些方法被错误地删除了。将以下内容添加到 proguard-rules.pro
.
-dontobfuscate
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable
-keepattributes *Annotation*
然后当您再次 运行 时,您将不会看到 j.c.f
,而是确切地知道删除了哪个方法。然后你可以告诉缩小器保留它。如果该方法在您自己的包中而不是在包含的库中,那么解决此问题的最懒惰的方法(我采用的方法)就是告诉 minifier 将所有方法保留在您的包中。因此,如果您的包裹是 com.ccbernardo
,则将其添加到 proguard-rules.pro
.
-keepclassmembers class com.ccbernardo.** {
public *;
protected *;
}
还有其他方法可以保留成员。例如,要保留所有带有注释 org.greenrobot.eventbus.Subscribe
的成员,请添加
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe public *;
}
我用这些是因为我不太了解ProGuard,所以我不知道如何让规则更具体。您可以在线阅读有关 ProGuard 语法的更多信息,但我希望这对您有所帮助。
我正在开发一个我正在使用 urbanairship 的应用程序,该应用程序构建正确并且安装也正确但是当它被初始化时某些东西会使它崩溃但只有当 minify 为真时,如果它为假它 运行 非常好。
错误:
我已经尝试实施 multidex 但没有成功
错误:
Process: qa.vodafone.myvodafone.prd, PID: 24925 java.lang.NoSuchMethodError: No virtual method object()Lj/c/f; in class Lj/c/f; or its super classes (declaration of 'j.c.f' appears in base.apk) at c.n.k.d.a(Unknown Source:0) at c.n.k.d.toString(Unknown Source:5) at com.urbanairship.job.AirshipService.a(:2) at c.n.i.h.a(:9) at c.n.s.c.a(:2)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
apply plugin: "com.soasta.mpulse.android"
android {
signingConfigs {
}
compileSdkVersion 28
defaultConfig {
applicationId ""
minSdkVersion 21
targetSdkVersion 28
versionCode 224
versionName "10.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debuggable = false
jniDebuggable = false
renderscriptDebuggable = false
signingConfig signingConfigs.releaseTest
}
}
flavorDimensions "default"
productFlavors {
}
def name = "mva"
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${name}_${variant.name}_${versionName}.apk"
}
}
lintOptions {
disable 'TypographyFractions', 'TypographyQuotes'
enable 'RtlHardcoded', 'RtlCompat', 'RtlEnabled'
check 'NewApi', 'InlinedApi'
quiet false
abortOnError true
ignoreWarnings true
checkAllWarnings true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.core:core-ktx:1.2.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "com.airbnb.android:lottie:$lottie_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
testImplementation 'org.mockito:mockito-core:1.10.19'
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
implementation "android.arch.lifecycle:livedata:1.1.1"
implementation "com.squareup.moshi:moshi-kotlin:1.8.0"
implementation "com.squareup.moshi:moshi-adapters:1.5.0"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1"
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.1.0'
implementation "com.google.android.gms:play-services-maps:${gmsServicesVersion}"
implementation "com.google.android.gms:play-services-location:${gmsServicesVersion}"
implementation "com.google.android.gms:play-services-analytics:${gmsServicesVersion}"
implementation 'com.google.android.libraries.places:places:2.0.0'
implementation 'com.google.maps:google-maps-services:0.2.4'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.biometric:biometric:1.0.0-alpha04'
implementation 'com.gauravbhola.ripplepulsebackground:library:1.0.0'
implementation 'me.everything:overscroll-decor-android:1.0.4'
// Airship SDK - FCM
implementation 'com.urbanairship.android:urbanairship-fcm:10.0.2'
// Firebase
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-iid:19.0.1'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
//Adobe Analytics
implementation 'com.adobe.mobile:adobeMobileLibrary:4.17.9'
//implementation 'com.adobe.marketing.mobile:sdk-core:1.4.0'
//implementation 'com.adobe.marketing.mobile:target:1.1.1'
// Tealium
implementation 'com.tealium:library:5.5.4'
implementation 'com.tealium:lifecycle:1.1.2'
implementation('com.soasta.mpulse:mpulse-android:2.6.3') {
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: "com.android.tools.build", module: "gradle"
}
//Zopim Chat
implementation group: 'com.zopim.android', name: 'sdk', version: '1.4.1'
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
implementation ('com.crashlytienter code herecs.sdk.android:crashlytics:2.10.1@aar') {
transitive = true
}
}
mpulseAndroid {
exclude ~/.*classes.jar/
}
根据我的了解,这是您在首次启用缩小时 运行 遇到的常见问题。缩小器(ProGuard 或 R8)会删除代码中未直接引用的任何方法,作为缩小 APK 工作的一部分。这个功能非常有用——当我第一次使用它时,它从我的 APK 中删除了很多未使用的方法,以至于我不再需要 MultiDex。
但这会导致问题 - 有时有些方法可能永远不会在您的代码中直接调用,而是通过反射或在生成的代码中调用,例如使用 Otto/EventBus 时的 @Subscribe
方法和 @OnClick
使用 ButterKnife 时的方法。缩小器也错误地删除了这些方法,你只有在构建和 运行ning 之后得到 NoSuchMethodError
时才会发现。更糟糕的是,您不知道哪个方法被错误地删除了,因为方法名称被 j.c.f
.
我是这样解决的。首先,禁用混淆,这样你就可以看到哪些方法被错误地删除了。将以下内容添加到 proguard-rules.pro
.
-dontobfuscate
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable
-keepattributes *Annotation*
然后当您再次 运行 时,您将不会看到 j.c.f
,而是确切地知道删除了哪个方法。然后你可以告诉缩小器保留它。如果该方法在您自己的包中而不是在包含的库中,那么解决此问题的最懒惰的方法(我采用的方法)就是告诉 minifier 将所有方法保留在您的包中。因此,如果您的包裹是 com.ccbernardo
,则将其添加到 proguard-rules.pro
.
-keepclassmembers class com.ccbernardo.** {
public *;
protected *;
}
还有其他方法可以保留成员。例如,要保留所有带有注释 org.greenrobot.eventbus.Subscribe
的成员,请添加
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe public *;
}
我用这些是因为我不太了解ProGuard,所以我不知道如何让规则更具体。您可以在线阅读有关 ProGuard 语法的更多信息,但我希望这对您有所帮助。