2011-10-04 155 views
0

我正在使用LayoutInflater.inflate(int resourceId,ViewGroup組)來誇大我的應用程序中的一些視圖。但是,當我困惑後運行的應用程序使用ProGuard我得到這個錯誤:混淆錯誤 - NoSuchMethodError:android.view.LayoutInflater.inflate

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

問題消失。但我需要第一個案例。你能幫我找到解決這個問題的辦法嗎?

+0

您是否使用android工具自動生成的cfg文件? –

+0

是的。我正在使用自動生成的cfg文件,對我的庫和一些類進行了一些更改,以便公開他們的字段和方法 – MistaGreen

+0

您可以發佈整個事情嗎? –

回答

0

最有可能的是,問題是由選項-ignorewarnings造成的。你應該看看警告並嘗試解決它們。如有必要,您仍然可以爲特定類別指定-dontwarn,這些類別您確定在執行程序期間從未實際使用過它們。

0

該proguard配置生成與舊版本的android SDK。更新到構建工具的最新版本,並通過命令行導航到你的項目(有AndroidManifest.xml中在它的目錄)的根目錄,然後鍵入以下內容:

android update project -p .

應該產生一個新的你可以檢查並確保「keepclasseswithmembernames」的實例更改爲「keepclasseswithmembers」(我認爲還有其他更改,但不確定)。看看是否修復它。

+0

我嘗試了,但沒有幫助。我反編譯的應用程序,發現mLayoutInflator.inflate(mUiResources.getLayout(mUiResources.getIdentifier(「main」,「layout」,mUiPackage)),null)變成l1.inflate(XmlRecourceParser,null)。我不明白爲什麼Android會看到這種方法。方法可從1 api級別:[LayoutInflator](http://developer.android.com/reference/android/view/LayoutInflater.html) – MistaGreen

+0

我正在使用您的proguard配置運行您的代碼,並且只是沒有看到此問題。您是否嘗試過*沒有* proguard?可能值得驗證的是,問題實際上是在混淆步驟。 –

+0

沒有proguard所有的工作完美。 – MistaGreen

0

升級到最新的ProGuard 4.6。當我使用ProGuard(即使是最新的)Android SDK時,也出現了類似的錯誤,但它不是最新的ProGuard版本。使用[ANDROID_SDK]/tool/proguard下的proguard文件夾下載並替換它。這解決了我的問題。不知道它是否也適用於你的情況,我的與充氣器無關,但是,我發現一個錯誤,它沒有任何意義(使用舊的ProGuard版本)。