在我的 Android 项目中,我使用gradle 3.1,添加了minifyEnabled true
并配置了 proguard-rules ,并且在我使用{{1 }}项目构建没有错误。但是后来我将Java 1.8支持添加到gradle中,然后该项目开始构建失败。同样,一旦我通过删除./gradlew clean build
和sourceCompatibility JavaVersion.VERSION_1_8
删除了Java 8支持,则该项目将使用targetCompatibility JavaVersion.VERSION_1_8
进行构建。我该如何解决这个问题。
我的 build.gradle 文件如下
./gradlew clean build
我的保护规则如下
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
buildscript {
repositories {
mavenCentral()
}
}
repositories {
mavenCentral()
}
android {
compileSdkVersion 28
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.rxtest.proguard"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//Looks great
implementation fileTree(include: ['*.jar'], dir: 'libs')
// Unit testing
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
// Google
implementation "com.android.support:appcompat-v7:$android_support_version"
implementation "com.android.support:design:$android_support_version"
// Constraint layout
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
// Tapadoo Alerter
implementation 'com.tapadoo.android:alerter:2.0.6'
// Networking
implementation 'com.squareup.retrofit2:converter-moshi:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
//RxJava
implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
//Android Architectural components
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
//HockeyApp
implementation 'net.hockeyapp.android:HockeySDK:5.1.0'
}
当我构建项目时,如下所示从终端接收到堆栈跟踪。
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-dontwarn java.lang.invoke.*
# Google
-keep class android.support.v7.widget.** { *; }
-keep interface android.support.v7.widget.** { *; }
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keep class com.rxtest.proguard.network.** { *; }
# OkHttp
-dontwarn org.codehaus.**
-dontwarn okhttp3.**
-dontwarn okio.**
#Retrofit
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-keep class com.facebook.** {
*;
}
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
#Stetho
-keep class com.facebook.stetho.** {
*;
}
任何解决此问题的线索都将受到热烈欢迎:)。