2016-08-23 88 views
4

我正在使用xamarin应用程序。当我能够在Android的特性 “的ProGuard”,而构建的应用程序,我得到了以下错误:Xamarin Android ProGuard Enable

"java.exe" exited with code1. 

enter image description here proguard的CFG文件有以下几点:

-keep public class * extends android.app.Activity 
-keep public class * extends android.app.Application 
-keep public class * extends android.app.Service 

开发环境:
Visual Studio 2015
Xamarin 4.0.4.4

+0

当你有错误?运行?编译时间?也添加你的proguard文件。 – AndroidRuntimeException

+2

您可以将您的完整诊断版本输出添加到您的问题中吗?错误应该有一个导致它的痕迹。 –

+2

我见过的最常见的问题与您的JDK版本有关(如果将其设置为诊断,您将在输出中看到该版本)以及堆大小不足。在他们的bug追踪器中仍然存在一些漏洞,即:https://bugzilla.xamarin.com/show_bug.cgi?id=35255 – silencedmessage

回答

12

我在启用ProGuard时遇到同样的问题。通过遵循关于this link的建议,我通过手动更新我的proguard来解决问题。这些步骤相当容易,他们解决了这个问题。希望这可以帮助你。

  1. 下载ProGuard zip文件可从:https://sourceforge.net/projects/proguard/files/。在撰写本文时,最新版本的ProGuard是5.3。
  2. ProGuard没有安装程序,因此您需要解压该文件并将proguard文件夹结构复制到以下步骤中标识的位置。
  3. 启动SDK管理器并记下菜单选项下方左上方的路径。在我的情况下,这是C:\ Users \ Sahar \ AppData \ Local \ Android \ android-sdk。 proguard文件夹位于此路径的tools文件夹中(在我的情况下,这是C:\ Users \ Sahar \ AppData \ Local \ Android \ android-sdk \ tools \ proguard)。
  4. 关闭所有可能访问SDK的开发环境,并将proguard文件夹重命名为proguard.old。
  5. 将新版本的proguard文件夹复制到工具文件夹中,并根据需要将其重命名为proguard(在我的情况下复制的文件夹已从proguard5.3重命名)。
  6. 最后将配置文件从proguard.old文件夹复制到新文件夹中。在我的情况下,这些是: - proguard-android.txt,proguard-android-optimize.txt和proguard-project.txt。
  7. 启用ProGuard后清理并重建项目。
+0

要做的最好的事情是张贴相关的详细信息**和**包括链接到页面。否则,不幸的是,如果链接失效,您的答案的有效性也会消失。 – gravity

+1

@gravity感谢您的建议,我刚刚开始用我所能提供的帮助,我将更新我的答案 –

+0

出色的编辑。现在有了很好的细节,并且因此得到了更好的答案。 – gravity

1

我有一个问题,Proguard正在从我的应用中删除Google Play服务库。

我不得不文本以下行添加到该文件夹​​中找到的proguard-android.txt文件:

/(Path to your Android SDK Folder)/tools/proguard

-keep public class com.google.android.gms.* { public *; } 
-dontwarn com.google.android.gms.** 

完整的ProGuard-android.txt文件

-keep public class com.google.android.gms.* { public *; } 
-dontwarn com.google.android.gms.** 

# This is a configuration file for ProGuard. 
# http://proguard.sourceforge.net/index.html#manual/usage.html 

-dontusemixedcaseclassnames 
-dontskipnonpubliclibraryclasses 
-verbose 

# Optimization is turned off by default. Dex does not like code run 
# through the ProGuard optimize and preverify steps (and performs some 
# of these optimizations on its own). 
-dontoptimize 
-dontpreverify 
# Note that if you want to enable optimization, you cannot just 
# include optimization flags in your own project configuration file; 
# instead you will need to point to the 
# "proguard-android-optimize.txt" file instead of this one from your 
# project.properties file. 

-keepattributes *Annotation* 
-keep public class com.google.vending.licensing.ILicensingService 
-keep public class com.android.vending.licensing.ILicensingService 

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native 
-keepclasseswithmembernames class * { 
    native <methods>; 
} 

# keep setters in Views so that animations can still work. 
# see http://proguard.sourceforge.net/manual/examples.html#beans 
-keepclassmembers public class * extends android.view.View { 
    void set*(***); 
    *** get*(); 
} 

# We want to keep methods in Activity that could be used in the XML attribute onClick 
-keepclassmembers class * extends android.app.Activity { 
    public void *(android.view.View); 
} 

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations 
-keepclassmembers enum * { 
    public static **[] values(); 
    public static ** valueOf(java.lang.String); 
} 

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

-keepclassmembers class **.R$* { 
    public static <fields>; 
} 

# The support library contains references to newer platform versions. 
# Don't warn about those in case this app is linking against an older 
# platform version. We know about them, and they are safe. 
-dontwarn android.support.** 

# Understand the @Keep support annotation. 
-keep class android.support.annotation.Keep 

-keep @android.support.annotation.Keep class * {*;} 

-keepclasseswithmembers class * { 
    @android.support.annotation.Keep <methods>; 
} 

-keepclasseswithmembers class * { 
    @android.support.annotation.Keep <fields>; 
} 

-keepclasseswithmembers class * { 
    @android.support.annotation.Keep <init>(...); 
}