Android 如何在 ProGuard 中使用 -dontwarn?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21123835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:01:10  来源:igfitidea点击:

How to use -dontwarn in ProGuard?

androidproguard

提问by morya

I am using android studio to build debug and release application. When i build debug/release application

我正在使用 android studio 构建调试和发布应用程序。当我构建调试/发布应用程序时

./gradlew assembleDebug

./gradlew assembleRelease

both build are created perfectly and run as well. Shows appropriate dialog box for debug or release

两个构建都完美地创建并运行。显示适当的调试或发布对话框

now i have added proguard details in build.gradle:

现在我在 build.gradle 中添加了 proguard 细节:

signingConfigs {
    myConfig {
           storeFile file("keystore.jks")
           storePassword "abc123!"
           keyAlias "androidreleasekey"
           keyPassword "pqrs123!"
    }
}

buildTypes {
    release {
        runProguard true
        proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        signingConfig signingConfigs.myConfig
    }
}
productFlavors {
    defaultFlavor {
        proguardFile 'proguard-rules.txt'
    }
}

Now it shows error in event log as

现在它在事件日志中显示错误为

Warning: there were 7 unresolved references to classes or interfaces. You may need to add missing library jars or update their versions. If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)

Warning: there were 2 unresolved references to program class members. Your input classes appear to be inconsistent. You may need to recompile the code.

(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember) :Flash Sales:proguardDefaultFlavorRelease FAILED

警告:有 7 个未解析的类或接口引用。您可能需要添加缺少的库 jar 或更新它们的版本。如果您的代码在没有丢失类的情况下运行良好,您可以使用“-dontwarn”选项抑制警告。(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass

警告:有 2 个未解析的对程序类成员的引用。您的输入类似乎不一致。您可能需要重新编译代码。

http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember):闪购:proguardDefaultFlavorRelease FAILED

If i turn the runProguard option to false then its running.

如果我将 runProguard 选项设置为 false,则它正在运行。

I have these questions:

我有这些问题:

1) is it ok to release apk with runProguard = false?

1) 可以使用 runProguard = false 发布 apk 吗?

2) How to use dontwarn while creating release build?

2) 如何在创建发布版本时使用 dontwarn?

采纳答案by swiftBoy

When I add new lib to project Generally this How I need to define for Progaurd.

当我向项目添加新库时,通常这是我需要为 Progaurd 定义的方式。

Let's say I am using Twitter4J lib then I add dontwarn this way.

假设我正在使用 Twitter4J lib,然后我以这种方式添加 dontwarn。

-keep class twitter4j.** { *; }

-dontwarn twitter4j.**

-保持类 twitter4j.** { *; }

-不要警告 twitter4j。​​*

回答by JJ Du Plessis

Put the -dontwarn lines in the proguard-rules.pro or proguard-rules.txt file.

将 -dontwarn 行放在 proguard-rules.pro 或 proguard-rules.txt 文件中。

Had to google this elsewhere since none of the answers included this info. Check the other answers for the specific lines you need for your case.

由于没有任何答案包含此信息,因此不得不在其他地方进行谷歌搜索。检查您的案例所需的特定行的其他答案。