我正在使用 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);
问题消失了。但我需要第一个案例。你能帮我找到解决这个问题的方法吗?