ProGuard在MoPub集成中导致错误 - Android Studio

时间:2014-12-24 10:02:42

标签: android android-studio proguard mopub

我在build.gradle(mopub-sdk)文件中添加了这个

buildTypes {
        release {
            runProguard true;
            proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard.txt')
        }
 }

我的proguard.txt文件是

# Keep public classes and methods.
-keepclassmembers class com.mopub.** { public *; }
-keep public class com.mopub.**
-keep class com.mopub.mobileads.**{*;}
-keep public class com.mopub.mobileads.MoPubInterstitial
-keep public class com.mopub.mobileads.MoPubView
-keep public class android.webkit.JavascriptInterface {}

# Keep interfaces
-keep interface com.mopub.mobileads.MoPubInterstitial.InterstitialAdListener
-keep interface com.mopub.mobileads.MoPubView.BannerAdListener


# Explicitly keep any custom event classes in any package.
-keep class * extends com.mopub.mobileads.CustomEventBanner {}
-keep class * extends com.mopub.mobileads.CustomEventInterstitial {}
-keep class * extends com.mopub.nativeads.CustomEventNative {}

# Support for Android Advertiser ID.
-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {*;}

但是在构建时,我收到了这个错误:

Error:(33, 45) error: cannot find symbol class InterstitialAdListener
Error:(35, 37) error: cannot find symbol class BannerAdListener

以及其他几个,但其中大部分与上述两个相关。这可能有什么问题?

1 个答案:

答案 0 :(得分:1)

如果您使用的是gradle插件的0.14.0或更高版本,则应替换" runProguard"用" minifyEnabled"在 build.gradle 文件中。

minifyEnabled false表示构建类型名称不能是main或androidTest(这是由插件强制执行的),并且它们必须彼此唯一。

只需更新:

 buildTypes {           
     release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
                }
            }

并更新您的类路径

classpath 'com.android.tools.build:gradle:0.13.+'