我正在尝试使用proguard创建一个可运行的JAR文件。当我使用Eclipse导出JAR时,一切正常,我有一个漂亮的JAR文件。
为了混淆,我使用命令行和命令java -jar ${ANDROID_SDK}/lib/proguard.jar @proguard-project.txt
但是当我尝试运行创建的JAR时,我得到的响应是
no main manifest attribute
我的proguard-project.txt如下
-injars bin/classes
-injars libs
-outjars bin/classes_processed.jar
-libraryjars proguard/android.jar
-dontwarn java.**
-keep class java.**
-dontwarn javax.**
-keep class javax.**
-dontwarn android.**
-keep class android.**
-dontwarn com.sun.**
-keep class com.sun.**
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
-dontnote
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keep public class com.app.main {
public static void main(java.lang.String[]);
}
-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.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
如有任何帮助,不胜感激
ProGuard本身不生成manifest。您必须手动创建一个,并像这样在配置中包含它:
-injars path/to/your/resources-dir
-injars ...
资源目录应该使用以下目录结构包含清单:
META-INF/Manifest.MF
如果您还混淆了jar的主类,则需要添加以下配置:
-adaptresourcefilecontents **.MF