android - Proguard 告诉我 'Please correct the above warnings first.' 。如何解决外部 jar 的引用?

标签 android proguard antbuilder

我该如何解决这些警告?

日志说

 [proguard] Note: duplicate definition of library class...
 ...
 [proguard] Note: there were 370 duplicate class definitions.
 [proguard] Initializing...
 [proguard] Warning: abc.cba..: can't find superclass or interface xyz.zyx....
 ...
 [proguard] Note: the configuration refers to the unknown class 'android.app.backup.BackupAgentHelper'...
 ...
 [proguard] Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlSerializer...
 ...

proguard.cfg
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public class !testAppH23.** { *; }

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

这里是
Android Ant Build with Proguard Enabled 控制台日志。请看链接
ant build console log

这是我的 build.xml(基本上是它的 android 原始 ant 脚本)。请看链接
TestAppH23 Android Ant Build With Proguard Enabled

本地属性
sdk.dir=C:\\androiddev\\android-sdk-windows

build.properties
proguard.config=proguard.cfg
key.store=testapph23-release.keystore
key.alias=alisname
key.store.password=storepassword
key.alias.password=aliaspassword

default.properties
target=android-7

我为长篇大论道歉。感谢任何有关正确方向的指导。

更新1
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="testAppH23.activity"
      android:versionCode="1"
      android:versionName="1.0">
    <application
        android:icon="@drawable/home"
        android:theme="@android:style/Theme.NoTitleBar"
        android:label="@string/app_name"
        >
        <activity
            android:name=".start.StartActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.Translucent"
            android:screenOrientation="portrait"
            android:launchMode="singleTask"
            >
            <intent-filter>
                <action
                    android:name="android.intent.action.MAIN"
                    >
                </action>
                <category
                    android:name="android.intent.category.LAUNCHER"
                    >
                </category>
            </intent-filter>
        </activity>
        .....
        <service android:name="com.abc.myjar.papi.PIntentService"></service>

        <service android:name=".service.XyzService"></service>

    </application>


    <uses-library android:name="org.apache.http.entity"/>
    <uses-library android:name="org.apache.http.james.mime4j"/>

    <uses-permission android:name="android.permission...."/>

    <uses-sdk android:minSdkVersion="7" />

</manifest>

最佳答案

您必须向 ProGuard 保证输入 jar 中的一些可疑结构是可以的。

您的程序代码在包 org.xmlpull.v1 中包含 Android 运行时类的副本或更好版本。如果没问题:

-dontwarn org.xmlpull.v1.**
-dontnote org.xmlpull.v1.**

您的程序代码在 org.apache.http 中包含 Android 运行时类的副本。如果没问题:
-dontnote org.apache.http.**

您在包示例中的程序代码是指 AWT,它在 Android 中不存在。如果没问题:
-dontwarn java.awt.**

您的 PostgreSQL 驱动程序引用了许多 Android 中不存在的 javax 类。如果没问题:
-dontwarn org.postgresql.**

等等...

参照。 ProGuard 手册 > Troubleshooting

最后,您的配置指定 -keep public class !testAppH23.** { *;} ,它保留所有公共(public)类,除了 testAppH23 中的那些,以及它们的公共(public)/ protected /私有(private)类成员,不会被缩小/优化/混淆。这可能会导致一些关于描述符类的(无害的)注释。为了保持一致性,您可能希望删除类的“public”,或者为类成员添加“public protected”。

关于android - Proguard 告诉我 'Please correct the above warnings first.' 。如何解决外部 jar 的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8074417/

相关文章:

android - 如何检测用户何时使用 FusedLocationProviderClient 关闭 GPS?

proguard - Proguard 什么时候可以优化枚举?

ant - Gradle的AntBuilder文档在哪里?

java - 如何将使用ant构建的特定android项目转换为gradle?

android - 无法使用 Ant 从外部 jar 构建多个 Android dex 文件

Android - TextView 居中定位

android - 将android应用程序连接到谷歌云

android - 基于 APK 签名限制 FCM 主题订阅

java - Proguard 是否删除未使用的代码(在 Android 上)

android - Proguard Aws s3 问题