cocos2dx 3.17海外sdk接入填坑全纪录 Appodeal(广告) SDK 接入(5)

Appodeal 是一个广告平台的集合,主要针对海外市场,集成的广告源比较全面,但是由于sdk的开发者是俄罗斯人,所以接入主要看文档,遇到问题沟通时需要英语基础,不过技术支持比较好,问题回复很快,cocos2dx继续接入Android原生,目前主流sdk为cocos定制的版本基本没有了,大部分都要接入平台原生的sdk了。

 

Appodeal Android sdk文档(需要科学上网)

https://www.appodeal.com/sdk/documentation?framework=1&full=1&platform=1

 

1:接入版本选择这个版本 MultiDex,避免出现Android64K溢出的问题

2:将jar文件和aar文件拷如到app/libs 文件夹下

3:在build.gradle中添加,注意用到google官方的包 版本号要一致,比如play-services-ads是15.0.0,play-services-location也必须是15.0.0。

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        flatDir {
            dirs 'libs'
        }
    }
}
dependencies {
//Appodeal start

compile 'com.google.android.gms:play-services-ads:15.0.0'
compile 'com.google.android.gms:play-services-location:15.0.0'

compile 'com.squareup.picasso:picasso:2.5.2' //for Inmobi
compile name: 'adcolony-sdk-3.2.1', ext: 'aar'
compile name: 'mmedia-6.4.0', ext: 'aar'
compile name: 'mobvista_alphab', ext: 'aar'
compile name: 'mobvista_appwall', ext: 'aar'
compile name: 'mobvista_appwallext', ext: 'aar'
compile name: 'mobvista_common', ext: 'aar'
compile name: 'mobvista_interstitial', ext: 'aar'
compile name: 'mobvista_mvdownloads', ext: 'aar'
compile name: 'mobvista_mvjscommon', ext: 'aar'
compile name: 'mobvista_mvnative', ext: 'aar'
compile name: 'mobvista_nativeex', ext: 'aar'
compile name: 'mobvista_offerwall', ext: 'aar'
compile name: 'mobvista_playercommon', ext: 'aar'
compile name: 'mobvista_reward', ext: 'aar'
compile name: 'mobvista_videocommon', ext: 'aar'
compile name: 'mobvista_videofeeds', ext: 'aar'

//Appodeal end

}

4:在Manifest添加

    android:configChanges="orientation|screenSize"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    android:configChanges="orientation|screenSize"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    android:configChanges="orientation|screenSize"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"/>

    
        
        
    


    android:theme="@android:style/Theme.Translucent.NoTitleBar" />


    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        tools:replace="android:theme" />

    android:hardwareAccelerated="true" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
    android:configChanges="keyboardHidden|orientation|screenSize" />


    android:configChanges="keyboardHidden|orientation|screenSize"
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    android:configChanges="keyboardHidden|orientation|screenSize" />
    android:configChanges="keyboardHidden|orientation|screenSize" />
    android:configChanges="keyboardHidden|orientation|screenSize" />
    android:configChanges="keyboardHidden|orientation|screenSize"/>

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:configChanges="keyboardHidden|orientation|screenSize"/>

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

    android:hardwareAccelerated="true"/>



    android:theme="@android:style/Theme" />

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:configChanges="orientation|keyboardHidden|screenSize" />

    android:theme="@android:style/Theme"
    android:configChanges="orientation|keyboardHidden|screenSize" />





    
        
    


    android:exported="true" android:process=":Metrica">
    
        
        
        
    

    

    android:enabled="true" android:exported="true">
    
        
    


    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:hardwareAccelerated="true" />
    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:hardwareAccelerated="false" />
    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:hardwareAccelerated="true" />
    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:hardwareAccelerated="false" />


    android:configChanges="keyboardHidden|orientation|screenSize"
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />

    android:configChanges="keyboardHidden|orientation|screenSize"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />

    android:configChanges="keyboardHidden|orientation|screenSize"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />


    android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

    android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>

    android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>


    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    android:configChanges="screenSize|orientation"
    android:screenOrientation="portrait" />
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="landscape"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="portrait" />

    android:configChanges="orientation|screenSize"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    android:configChanges="keyboard|orientation"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />


    android:hardwareAccelerated="true" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />





    android:theme="@android:style/Theme.Translucent.NoTitleBar" android:hardwareAccelerated="true" />


    android:hardwareAccelerated="true" />

    android:hardwareAccelerated="true" android:theme="@android:style/Theme.Translucent" />

    android:hardwareAccelerated="true" android:theme="@android:style/Theme.Translucent" />


    android:hardwareAccelerated="true"/>

    android:hardwareAccelerated="true"/>

    android:hardwareAccelerated="true" android:resizeableActivity="false" android:theme="@android:style/Theme.NoTitleBar" />

    
        
    



    
        
    


    android:hardwareAccelerated="true" android:theme="@android:style/Theme.Translucent.NoTitleBar">
    
        
        
    



    
        
        
        
    



    android:name="io.presage.provider.PresageProvider"
    android:authorities="${applicationId}.PresageProvider"
    android:enabled="true"
    android:exported="true" />


    android:name="com.millennialmedia.internal.utils.MediaContentProvider"
    android:authorities="${applicationId}.MediaContentProvider"
    android:grantUriPermissions="true"
    android:exported="false" />



 
 
 




5:在 Manifest中有个tools错误,就是没有添加命名空间,加上这句 :xmlns:tools="http://schemas.android.com/tools",在manifest标签下,另外,在unity3d中也会经常出现这个问题,解决方法是相同的。


6:添加忽略混淆,如果遇到找不到类的情况,一定要添加这个选项

# Appodeal
-keep class com.appodeal.** { *; }
-keep class org.nexage.** { *; }
-keepattributes EnclosingMethod, InnerClasses, Signature, JavascriptInterface

# Amazon
-keep class com.amazon.** { *; }
-dontwarn com.amazon.**

# Mopub
-keep public class com.mopub.**
-keepclassmembers class com.mopub.** { public *; }
-dontwarn com.mopub.**
-keep class * extends com.mopub.mobileads.CustomEventBanner {}
-keepclassmembers class com.mopub.mobileads.CustomEventBannerAdapter {!private !public !protected *;}
-keep class * extends com.mopub.mobileads.CustomEventInterstitial {}
-keep class * extends com.mopub.nativeads.CustomEventNative {}
-keep class * extends com.mopub.mobileads.CustomEventRewardedVideo {}
-keepclassmembers class ** { @com.mopub.common.util.ReflectionTarget *; }
-dontwarn com.mopub.volley.toolbox.**

# Applovin
-keep class com.applovin.** { *; }
-dontwarn com.applovin.**

# Facebook
-keep class com.facebook.ads.** { *; }
-keeppackagenames com.facebook.*
-dontwarn com.facebook.ads.**

# Chartboost
-keep class com.chartboost.** { *; }
-dontwarn com.chartboost.**

# Unity Ads
-keepattributes SourceFile,LineNumberTable
-keep class com.unity3d.** { *; }
-dontwarn com.unity3d.**

# Yandex
-keep class com.yandex.metrica.** { *; }
-dontwarn com.yandex.metrica.**
-keep class com.yandex.mobile.ads.** { *; }
-dontwarn com.yandex.mobile.ads.**
-keepattributes *Annotation*

# StartApp
-keep class com.startapp.** { *;}
-dontwarn com.startapp.**
-dontwarn android.webkit.JavascriptInterface
-keepattributes Exceptions, InnerClasses, Signature, Deprecated, SourceFile, LineNumberTable, *Annotation*, EnclosingMethod

# Flurry
-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod,Signature
-keepclasseswithmembers class * {
  public (android.content.Context, android.util.AttributeSet, int);
}

# Avocarrot
-keep class com.avocarrot.** { *; }
-keepclassmembers class com.avocarrot.** { *; }
-dontwarn com.avocarrot.**
-keep public class * extends android.view.View {
  public (android.content.Context);
  public (android.content.Context, android.util.AttributeSet);
  public (android.content.Context, android.util.AttributeSet, int);
  public void set*(...);
}

# Adcolony
-keep class com.jirbo.adcolony.** { *;}
-keep class com.adcolony.** { *;}
-keep class com.immersion.** { *;}
-dontnote com.immersion.**
-dontwarn android.webkit.**
-dontwarn com.jirbo.adcolony.**
-dontwarn com.adcolony.**
-keepclassmembers class com.adcolony.sdk.ADCNative** { *; }

# Vungle
-keepattributes *Annotation*, Signature
-keep class com.vungle.** { *;}
-dontwarn com.vungle.**
-dontnote com.vungle.**
-dontwarn com.moat.**
-keep class com.moat.analytics.mobile.vng.** { *;}
-keep class com.moat.** { public protected private *; }
-keep class dagger.**
-dontwarn de.greenrobot.event.util.**
-keep class de.greenrobot.event.**
-keep class javax.inject.**
-keep class rx.**
-dontwarn rx.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
   long producerIndex;
   long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
   rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
   rx.internal.util.atomic.LinkedQueueNode consumerNode;
}

# MyTarget
-keep class com.my.target.** { *; }
-dontwarn com.my.target.**

# Mobvista
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.mobvista.** {*; }
-keep interface com.mobvista.** {*; }
-keep class android.support.v4.** { *; }
-dontwarn com.mobvista.**
-keep class **.R$* { public static final int mobvista*; }
-keep class com.alphab.** {*; }
-keep interface com.alphab.** {*; }

# Admob
-keep class com.google.android.gms.ads.** { *; }

# Tapjoy
-keep class com.tapjoy.** { *; }
-dontwarn com.tapjoy.**

# IronSource
-keepclassmembers class com.ironsource.sdk.controller.IronSourceWebView$JSInterface { public *; }
-keepclassmembers class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; }
-keep public class com.google.android.gms.ads.** { public *; }
-dontwarn com.moat.**
-keep class com.moat.** { public protected private *; }
-keep class com.ironsource.** { *; }
-dontwarn com.ironsource.**

# AdColonyV3
-keepclassmembers class * { @android.webkit.JavascriptInterface ; }
-keep class com.adcolony.** { *; }
-dontwarn com.adcolony.**
-dontwarn android.app.Activity

#Appnext
-keep class com.appnext.** { *; }
-dontwarn com.appnext.**

# Inmobi
-keep class com.inmobi.** { *; }
-dontwarn com.inmobi.**
-dontwarn com.squareup.picasso.**
-keep class com.squareup.picasso.** {*;}
-dontwarn com.squareup.picasso.**
-dontwarn com.squareup.okhttp.**
-keep class com.moat.** {*;}
-dontwarn com.moat.**

# MMdeia
-keepclassmembers class com.millennialmedia** {public *;}
-keep class com.millennialmedia**
-dontwarn com.millennialmedia.**

# Ogury
-dontwarn io.presage.**
-dontnote io.presage.**
-dontwarn shared_presage.**
-dontwarn org.codehaus.**
-keepattributes Signature
-keep class shared_presage.** { *; }
-keep class io.presage.** { *; }
-keepclassmembers class io.presage.** { *; }
-keepattributes *Annotation*
-keepattributes JavascriptInterface
-keepclassmembers class * {
  @android.webkit.JavascriptInterface ;
}
-dontnote okhttp3.**
-dontnote okio.**
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

-dontnote sun.misc.Unsafe
-dontnote android.net.http.*

-dontnote org.apache.commons.codec.**
-dontnote org.apache.http.**

-dontwarn org.apache.commons.collections.BeanMap
-dontwarn java.beans.**
-dontnote com.google.gson.**
-keepclassmembers class * implements java.io.Serializable {
  static final long serialVersionUID;
  private static final java.io.ObjectStreamField[] serialPersistentFields;
  private void writeObject(java.io.ObjectOutputStream);
  private void readObject(java.io.ObjectInputStream);
  java.lang.Object writeReplace();
  java.lang.Object readResolve();
}

# Google
-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.android.gms.ads.identifier.** { *; }
-dontwarn com.google.android.gms.**

# Legacy
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.net.http.**

# Google Play Services library
-keep class * extends java.util.ListResourceBundle {
  protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
  public static final *** NULL;
}
-keepnames class * implements android.os.Parcelable
-keepclassmembers class * implements android.os.Parcelable {
  public static final *** CREATOR;
}
-keep @interface android.support.annotation.Keep
-keep @android.support.annotation.Keep class *
-keepclasseswithmembers class * {
  @android.support.annotation.Keep ;
}
-keepclasseswithmembers class * {
  @android.support.annotation.Keep ;
}
-keep @interface com.google.android.gms.common.annotation.KeepName
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
  @com.google.android.gms.common.annotation.KeepName *;
}
-keep @interface com.google.android.gms.common.util.DynamiteApi
-keep public @com.google.android.gms.common.util.DynamiteApi class * {
  public ;
  public ;
}
-keep class com.google.android.gms.common.GooglePlayServicesNotAvailableException {*;}
-keep class com.google.android.gms.common.GooglePlayServicesRepairableException {*;}

# Google Play Services library 9.0.0 only
-dontwarn android.security.NetworkSecurityPolicy
-keep public @com.google.android.gms.common.util.DynamiteApi class * { *; }

# support-v4
-keep class android.support.v4.app.Fragment { *; }
-keep class android.support.v4.app.FragmentActivity { *; }
-keep class android.support.v4.app.FragmentManager { *; }
-keep class android.support.v4.app.FragmentTransaction { *; }
-keep class android.support.v4.content.ContextCompat { *; }
-keep class android.support.v4.content.LocalBroadcastManager { *; }
-keep class android.support.v4.util.LruCache { *; }
-keep class android.support.v4.view.PagerAdapter { *; }
-keep class android.support.v4.view.ViewPager { *; }
-keep class android.support.v4.content.ContextCompat { *; }

# support-v7-recyclerview
-keep class android.support.v7.widget.RecyclerView { *; }
-keep class android.support.v7.widget.LinearLayoutManager { *; }
 

最后,广告的sdk已接入成功,吐槽一下,这个广告在开始加载的时候,会造成程序的卡顿,1,2秒钟,而且这是个广告源的合集,不能删除里面的广告源,这个会造成包体变大,cocos还好,unity3d包体会增加近10M左右。

 

 

如有错误,大家可以一起交流

 联系方式 qq: 940299880

 

 

 

 

 

 

你可能感兴趣的:(cocos2dx项目实战与维护)