接入指南
概述
本页主要介绍工程配置注册事项
1.Gradle依赖
在App 的 build.gradle 文件中加入对应的依赖
implementation 'io.github.adgocompany:unad_cn:2.6.8'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.protobuf.nano:protobuf-javanano:3.1.0'
implementation 'com.google.code.gson:gson:2.8.1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
2. 配置maven
maven {
url "https://s01.oss.sonatype.org/content/repositories/releases/"
}
3. 初始化SDK
注意:在 Application 的 onCreate
方法中调用初始化方法,传入UNAD的 appid
单进程进行初始化
***
测试TEST_APPID 应用上线时请替换为正式的applicationId*
请主线程中初始化unad,参考DEMO
UNAD.initialize(new UNADConfig.Builder()
// true-屏蔽个性化推荐广告(关闭)
//false-不屏蔽个性化推荐广告(打开)
//默认false
.disablePersonalRecommand(false)
.setDebug(true).build(),
"TEST_APPID", this, new UNAD.InitCallback() {
@Override
public void onSuccess() {
Log.e("unadsdk", "UI:onSuccess");
}
@Override
public void onError(UnadError error) {
Log.e("unadsdk", "UI:onError");
}
});
4. 修改AndroidManifest.xml文件, 添加必要权限
添加访问权限
在AndroidManifest.xml文件中添加
SDK不强制校验下列权限(即:无下面权限sdk也可正常工作),但建议开发者申请下面权限,尤其是READ_PHONE_STATE权限 READ_PHONE_STATE权限用于允许SDK获取用户标识
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<!--获取设备标识IMEI。⽤于标识⽤户-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- 如果需要精确定位的话请加上此权限 不强制要求-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- 如果视频广告使用textureView播放,请务必添加,否则黑屏 -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- 此权限在Android R系统上判定广告对应的应用是否在用户的app上安装,避免投放错误的广告,以此提高用户的广告体验。若添加此权限,需要在您的用户隐私文档中声明! -->
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
<!--获取MAC地址,⽤于标识⽤户-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!--SDK内自定义的权限,与下载相关,aar中已经申请 快手需要-->
<permission
android:name="${applicationId}.permission.KW_SDK_BROADCAST"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.KW_SDK_BROADCAST" />
添加APPLICATION_ID 配置
在AndroidManifest.xml文件的application节点下添加
注意applicationId应该与您的应用包名一样,不一致可能会闪退
<uses-library android:name="org.apache.http.legacy" android:required="false" />
<uses-sdk tools:overrideLibrary="com.octopus.ad" />
<provider
android:name="com.qq.e.comm.GDTFileProvider"
android:authorities="${applicationId}.gdt.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/gdt_file_path" />
</provider>
<provider
android:name="com.bytedance.sdk.openadsdk.TTFileProvider"
android:authorities="${applicationId}.TTFileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/tt_file_paths" />
</provider>
<provider
android:name="com.bytedance.sdk.openadsdk.multipro.TTMultiProvider"
android:authorities="${applicationId}.TTMultiProvider"
android:exported="false" />
#h5广告入口
<activity
android:name="com.unad.sdk.GameAdActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="stateHidden|stateAlwaysHidden"
>
</activity>
build.gradle添加Java 1.8兼容性
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/io.netty.versions.properties' // will not include LICENSE file
exclude 'META-INF/INDEX.LIST' // will not include INDEX.LIST file
}
5. 混淆
如果需要混淆,添加下面配置
-ignorewarnings
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#unad
-keep class com.unad.sdk.** {*;}
#aliyun
-keep class com.aliyun.sls.android.producer.* { *; }
-keep interface com.aliyun.sls.android.producer.* { *; }
-dontwarn com.androidquery.**
-keep class com.androidquery.** { *;}
-dontwarn tv.danmaku.**
-keep class tv.danmaku.** { *;}
-dontwarn androidx.**
#tbs版本的sdk需要进行以下配置
-keep class com.tencent.smtt.** { *; }
-dontwarn dalvik.**
-dontwarn com.tencent.smtt.**
-keep class com.tencent.mm.opensdk.** {
*;
}
-keep class com.tencent.wxop.** {
*;
}
-keep class com.tencent.mm.sdk.** {
*;
}
# 穿山甲
-keep class com.pgl.sys.ces.** {*;}
-keep class com.bytedance.embed_dr.** {*;}
-keep class com.bytedance.embedapplog.** {*;}
-keep class com.bytedance.sdk.openadsdk.** { *; }
-keep class com.androidquery.callback.** {*;}
-keep public interface com.bytedance.sdk.openadsdk.downloadnew.** {*;}
-keep class com.ss.sys.ces.* {*;}
-dontwarn com.ss.android.socialbase.downloader.**
-dontwarn com.ss.android.crash.log.**
# MTG
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.mintegral.** {*; }
-keep interface com.mintegral.** {*; }
-keep class android.support.v4.** { *; }
-dontwarn com.mintegral.**
-keep class **.R$* { public static final int mintegral*; }
-keep class com.alphab.** {*; }
-keep interface com.alphab.** {*; }
# 快手
-keep class org.chromium.** {*;}
-keep class org.chromium.** { *; }
-keep class aegon.chrome.** { *; }
-keep class com.kwai.**{ *; }
-dontwarn com.kwai.**
-dontwarn com.kwad.**
-dontwarn com.ksad.**
-dontwarn aegon.chrome.**
-keep class com.kwad.sdk.** { *;}
-keep class com.ksad.download.** { *;}
-keep class com.kwai.filedownloader.** { *;}
# qapm 平台
-keep class com.tencent.qapmsdk.**{*;}
-dontwarn com.tencent.qapmsdk.**
-dontnote com.tencent.qapmsdk.**
-ignorewarnings
#klevin
-keep class com.tencent.tgpa.lite.**{*;}
-keep class com.ihoc.mgpa.deviceid.**{*;}
-keep class com.tencent.klevin.**{*;}
#baidu
-dontwarn com.baidu.mobads.sdk.api.**
-keep class com.baidu.ad.magic.flute.** {*;}
-keep class com.baidu.mobstat.forbes.** {*;}
-keep class com.baidu.mobads.** { *; }
########### 移动安全联盟 OAID 混淆要求 begin ########
-keep class XI.CA.XI.**{*;}
-keep class XI.K0.XI.**{*;}
-keep class XI.XI.K0.**{*;}
-keep class XI.vs.K0.**{*;}
-keep class XI.xo.XI.XI.**{*;}
-keep class com.asus.msa.SupplementaryDID.**{*;}
-keep class com.asus.msa.sdid.**{*;}
-keep class com.bun.lib.**{*;}
-keep class com.bun.miitmdid.**{*;}
-keep class com.huawei.hms.ads.identifier.**{*;}
-keep class com.samsung.android.deviceidservice.**{*;}
-keep class com.zui.opendeviceidlibrary.**{*;}
-keep class org.json.**{*;}
-keep public class com.netease.nis.sdkwrapper.Utils {
public<methods>;
}
########### 移动安全联盟 OAID 混淆要求 end ########
#京东sdk混淆规则
-keep class com.jd.ad.sdk.** { *; }
如果您的资源混淆或资源缩减,您需要保留SDK的资源,SDK的资源名都是以ksad_开头的。
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@layout/ksad_*,@id/ksad_*,@style/ksad_*,
@drawable/ksad_*,@string/ksad_*,@color/ksad_*,@attr/ksad_*,@dimen/ksad_*"
/>
-keep class com.koms.fert.co.mpd.**{*;}
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
资源白名单
"R.anim.klevin_*"
"R.color.klevin_*"
"R.drawable.klevin_*"
"R.id.klevin_*"
"R.layout.klevin_*"
"R.mipmap.klevin_*"
"R.string.klevin_*"
"R.integer.klevin_*"
"R.style.klevin_*"
"R.dimen.klevin_*"
"R.xml.klevin_*"
-dontwarn com.octopus.ad.**
-keep class com.octopus.ad.** {*;}
# 使用Glide要添加的混淆
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.squareup.picasso.** { *; }
注意:平台SDK包中whiteList.txt 白名单上的资源不支持混淆
6. 选择支持的NDK
ndk { // 设置支持的 SO 库构架,注意这里要根据你的实际情况来设置
abiFilters ‘armeabi-v7a’, ‘arm64-v8a’, ‘x86’, ‘x86_64’, ‘armeabi’
}
注意:请开发者务必按照上面信息进行注册声明,详情见Demo。