Xamarin.Android Proguard – 不受支持的类版本号52.0
我试图在我的Xamarin.Android项目中使用Proguard,但编译失败,错误Unsupported class version number [52.0] (maximum 51.0, Java 1.7)
我从这两个 问题中看到,它可能是Java 7和Java 8之间的不匹配,更确切地说,某些版本的proguard不支持Java 8.但是,在Xamarin首选项 – > SDK位置中,Java SDK指向JDK 7: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
有什么地方可以更精确地configurationproguard吗? 任何其他的想法?
这里是失败日志:
java.io.IOException:无法读取[/Library/Frameworks/Xamarin.Android.framework/Versions/7.0.0-18/lib/xbuild-frameworks/MonoAndroid/v7.0/mono.android.jar](Can在proguard.InputReader.readInput(InputReader.java:230)at proguard.InputReader.readInput()方法类[android / app / ActivityTracker.class](不支持的类版本号[52.0](最大51.0,Java 1.7))) InputReader.java:200)在proguard.InputReader.readInput(InputReader.java:178)在proguard.InputReader.execute(InputReader.java:78)在proguard.ProGuard.readInput(ProGuard.java:196)在proguard.ProGuard。执行(ProGuard.java:78)在proguard.ProGuard.main(ProGuard.java:492)导致:java.io.IOException:无法处理类[android / app / ActivityTracker.class](不支持的类版本号[ 52.0](最大51.0,Java 1.7))在proguard.io.ClassReader.read(ClassReader.java:112)在proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)在proguard.io.JarReader.read(JarReader .java:65)在proguard.io.Director ypump.readFiles(DirectoryPump.java:65)在proguard.io.DirectoryPump.pumpDataEntries(DirectoryPump.java:53)在proguard.InputReader.readInput(InputReader.java:226)… 6 more引起:java.lang。 UnsupportedOperationException:在proguard.classfile.io.ProgramClassReader.visitProgramClass(ProgramClassReader.java:88)上的proguard.classfile.util.ClassUtil.checkVersionNumbers(ClassUtil.java:140)处的不支持的类版本号[52.0](最大值51.0,Java 1.7)在proguard.classfile.ProgramClass.accept(ProgramClass.java:346)在proguard.io.ClassReader.read(ClassReader.java:91)… 11更多
9警告1错误(s)
您需要使用最新版本的Proguard更新默认的Android SDK proguard.jar
:
https://sourceforge.net/projects/proguard/files/
我build议你安装在android-sdk\tools\proguard
中的默认版本的一侧。 只需将现有文件夹重命名为其他内容并添加新版本的proguard
。
这在Xamarin.Android 7.0发行说明中列出:
https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.0/
其中还logging了以下错误:
https://bugzilla.xamarin.com/show_bug.cgi?id=44187
这与Xamarin.Android存储库中的合并请求协调:
简单的答案
根据文档你需要更新proguard版本(从版本5开始,它支持Java 8),并确保你使用jdk1.8
JDK 1.8 – 高达API 24+
JDK 1.7 – 直到API 23
JDK 1.6 – 直到API 20
如何从包控制台更新写这个命令
PM> Install-Package name.atsushieno.proguard.facebook
https://www.nuget.org/packages/name.atsushieno.proguard.facebook
或手动下载proguard并用当前版本replace
YOUR_SDK – > tools – > proguard – >(删除所有旧文件,解压缩新版本)
详细的答案,如果你启用目标android Nogut,并启用Multi-Dex或ProGuard你需要使用适当的ProGuard版本(因为ToolMakerSteve说,他们依赖于ProGuard),所以确保你的工具从目标java 8 – >选项 – > xamarin – > Java并更新ProGuard版本
更新答案
确保您的支持库版本与目标版本兼容,如果您的目标
Android 7 (api 24)意味着你的支持库应该是24
Android 7.1 (api 25)意味着你的支持库应该是25
到所有的支持库,如果你使用谷歌播放服务
我也在我的Windows 10 x64和Visual Studio 2015面临同样的问题。我已经设置JDK的pathJDK 1.8下的Visual Studio工具 – >选项 – > Xamarin – > Java开发工具包位置的Android设置。 它指向“C:\ Program Files文件(x86)\ Java \ jdk1.7.0_55”,并将其设置为“C:\ Program Files \ Java \ jdk1.8.0_31”,问题已得到解决。
我遇到了Proguard从我的应用中删除Google Play服务库的问题。
除了上面的@Jon Douglas的回答之外,我不得不将以下几行文本添加到这个文件夹中的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>(...); }