0

我正在一一分享我的配置。

从我的 Gradle 文件中:

 ext.kotlin_version = '1.3.31'
 dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
project.ext {
    targetSdkVersion = 25
    compileSdkVersion = 28
    coreMinSdk = 17
    eventbusVersion = '3.1.1'
}
// gradle wrapper:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

我的 proguard 脚本:

proguard-rules.pro我已经在我的文件夹中的文件中尝试了以下语句的每一行/app

-keep class com.my_package.layout.** { *; }
-keepnames class com.my_package.layout.MyCustomClass
-keepclassmembers class com.my_package.layout.MyCustomClass {
   public *;
}
-keep class com.my_package.layout.MyCustomClass
-keep public class com.my_package.layout.MyCustomClass {
    public *;
}

请注意,这com.my_package.layout.MyCustomClass是一个有效的 LinearView 扩展类。我在我的布局 XML 中使用它。当我创建并运行它时,没有错误。这个类工作正常。

发布方式:

buildTypes {
        release{
            debuggable false
            jniDebuggable false
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    ...
    }
  ...
}

但是在发布版本中,当 minifyEnabled 为 true 时,proguard 脚本不起作用。它不保留此文件。有一个运行时异常说这个文件不能被膨胀。因此,该应用程序崩溃了。

历史:

之前没有 proguard 脚本。当时在app crash中报android.view.InflateException。

我按照此文档两次:了解 -keep 指令 ,然后我将脚本一一放上。除非我修改,否则此错误不会消失:minifyEnabled = false

2021-11-16 17:19:40.445 32158-32158/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.my_package, PID: 32158 java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.my_package/com.my_package.dashboard.ActivityDashboard}:
android.view.InflateException: Binary XML file line #37 in 
com.my_package:layout/activity_dashboard: Binary XML file line #37 in 
com.my_package:layout/activity_dashboard: Error inflating class 
com.my_package.layout.MyCustomClass
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
  ...

请帮忙。

4

0 回答 0