开发者

Obfuscation error - NoSuchMethodError: android.view.LayoutInflater.inflate

I'm using LayoutInflater.inflate(int resourceId, ViewGroup group) to inflate some views in my app. But when I run app after obfuscation with proguard I've got this error:

ERROR/AndroidRuntime(30511): java.lang.NoSuchMethodError: android.view.LayoutInflater.inflate

This is my proguard config:

-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 *;
}

I realized, that app crashes on this line:

setContentView(mLayoutInflator.inflate(mUiResources.getLayout(mUiResources.getIdentifier("main", "layout", 开发者_运维技巧mUiPackage)), null));

Whole picture:

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));

If I changed problem string with

setContentView(R.layout.main);

Problem disappeared. But I need first case. Could you help me find solution for this problem?


Most likely, the problem is caused by the option -ignorewarnings. You should look at the warnings and try to solve them. If necessary, you can still specify -dontwarn for particular classes of which you're sure that they are never actually used during the execution of the program.


That proguard config was generated with an older version of the android SDK. update to the newest version of the build tools, and from a command line navigate to the root directory of your project (the dir with AndroidManifest.xml in it) and type the following:

android update project -p .

It should generate a new proguard config file for you- you can check and make sure that instances of "keepclasseswithmembernames" changes to "keepclasseswithmembers" (I think there are other changes too, but not sure). See if that fixes it.


Upgrade to the latest ProGuard 4.6. I had similar error when I used the ProGuard that came (even with the latest) Android SDK, but it wasn't the latest ProGuard version. Download and replace it with the proguard folder under [ANDROID_SDK]/tool/proguard. That fixed the problem for me. Not sure if it also works in your case, mine was not related to inflaters, however, I got an error where it just didn't make any sense (with the old ProGuard version).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜