【问题标题】:Obfuscation error - NoSuchMethodError: android.view.LayoutInflater.inflate混淆错误 - NoSuchMethodError: android.view.LayoutInflater.inflate
【发布时间】: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


【解决方案1】:

问题很可能是由选项-ignorewarnings 引起的。您应该查看警告并尝试解决它们。如有必要,您仍然可以为您确定在程序执行期间从未实际使用过的特定类指定 -dontwarn

【讨论】:

    【解决方案2】:

    该 proguard 配置是使用旧版本的 android SDK 生成的。更新到最新版本的构建工具,并从命令行导航到项目的根目录(其中包含 AndroidManifest.xml 的目录)并键入以下内容:

    android更新项目-p.

    它应该为您生成一个新的 proguard 配置文件 - 您可以检查并确保“keepclasseswithmembernames”的实例更改为“keepclasseswithmembers”(我认为还有其他更改,但不确定)。看看能不能解决。

    【讨论】:

    • 我尝试过,但没有帮助。我反编译了应用程序,发现 mLayoutInflator.inflate(mUiResources.getLayout(mUiResources.getIdentifier("main", "layout", mUiPackage)), null) 变成了 l1.inflate(XmlRecourceParser, null)。而且我不明白为什么Android确实看到了这种方法。 1个api级别可用的方法:LayoutInflator
    • 我正在使用你的 proguard 配置运行你的代码,只是没有看到这个问题。你试过没有 proguard吗?可能值得验证问题实际上在于混淆步骤。
    【解决方案3】:

    升级到最新的 ProGuard 4.6。当我使用附带的(即使是最新的)Android SDK 的 ProGuard 时,我也遇到了类似的错误,但它不是最新的 ProGuard 版本。下载并替换为 [ANDROID_SDK]/tool/proguard 下的 proguard 文件夹。这解决了我的问题。不确定它是否也适用于您的情况,我的与充气机无关,但是,我收到一个错误,它没有任何意义(使用旧的 ProGuard 版本)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 2013-04-12
      • 2019-10-15
      相关资源
      最近更新 更多