【发布时间】:2011-10-04 22:00:04
【问题描述】:
我正在使用 LayoutInflater.inflate(int resourceId, ViewGroup group) 为我的应用中的一些视图充气。但是当我用 proguard 混淆后运行应用程序时,我遇到了这个错误:
ERROR/AndroidRuntime(30511): java.lang.NoSuchMethodError: android.view.LayoutInflater.inflate
这是我的 proguard 配置:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-ignorewarnings
-libraryjars ...
-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 com.android.vending.licensing.ILicensingService
-keep public class ...
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
我意识到,应用程序在这一行崩溃了:
setContentView(mLayoutInflator.inflate(mUiResources.getLayout(mUiResources.getIdentifier("main", "layout", mUiPackage)), null));
全图:
String mUiPackage = mSettings.getString(mResources.getString(R.string.ui_package), getPackageName());
try {
mUiResources = getPackageManager().getResourcesForApplication(mUiPackage);
} catch (NameNotFoundException e) {}
try {
mUiContext = getApplicationContext().createPackageContext(mUiPackage, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
mLayoutInflator = (LayoutInflater) mUiContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} catch (NameNotFoundException e) {}
setContentView(mLayoutInflator.inflate(mUiResources.getLayout(mUiResources.getIdentifier("main", "layout", mUiPackage)), null));
如果我用
更改了问题字符串setContentView(R.layout.main);
问题消失了。但我需要第一个案例。你能帮我找到解决这个问题的方法吗?
【问题讨论】:
-
你使用的是android工具自动生成的cfg文件吗?
-
是的。我正在使用自动生成的 cfg 文件,对我的库和一些类进行了一些更改,以公开它们的字段和方法
-
那你能把整件事都贴出来吗?
标签: android obfuscation proguard inflate nosuchmethoderror