SDK configuration
Please follow the steps below to introduce the required configuration for integrating the SDK, skipping or omitting it will cause the integration to fail.
Permission configuration
<manifest >
<!--TradPlus SDK general necessary permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
(1)CN Network SDK
- If you're integrating the CN SDK, you need to add these extra permissions:
<!--Kuaishou、Sigmob、Youdao、MTG CN-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--Kuaishou、Baidu-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!--Kuaishou、Baidu、MTG CN-->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!-- MTG CN、CSJ will use this permission to determine whether the application corresponding to the advertisement is installed on the user's app on the Android R system, so as to avoid placing false advertisements, so as to improve the user's advertising experience.-->
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
- CSJ SDK - necessary permissions
<!--Necessary permissions to solve security risk vulnerabilities, sending and registering broadcast events requires calling an interface with transfer permissions-->
<permission
android:name="${applicationId}.openadsdk.permission.TT_PANGOLIN"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.openadsdk.permission.TT_PANGOLIN" />
<!-- If the video ad is played using a textureView, be sure to add it, otherwise a black screen -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
(2)Overseas Network SDK
- Pangle SDK——necessary permissions
<!--If the video ad is played using a textureView, be sure to add it, otherwise a black screen -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
- Android 12 and above, agree to get Android Advertiser Identifier:
<uses-permission android:name="android.permission.Ad_ID" />
(3)Optional permissions
- Apply for the following permissions for the anti-cheating function and help the advertising platform to serve ads
<!--Optional permission, used for anti-cheating function and helpful for advertising platform to place ads-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Manifest Provider
The configuration statement is the compatibility processing performed by the third-party platform in order to make the advertisement display normally. The developer adds the corresponding <meta-data>
and <provider>
elements in the following positions according to the connected advertisement source.
<manifest>
<application>
<meta-data
.../>
<provider
...
</provider>
</application>
</manifest>
(1)Google Admob
- Add your AdMob app ID (identified in the AdMob UI) to your app's AndroidManifest.xml file. To do so, add a
<meta-data>
tag with android:name="com.google.android.gms.ads.APPLICATION_ID". You can find your app ID in the AdMob UI. For android:value, insert your own AdMob app ID, surrounded by quotation marks.
<!--Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713-->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
(2)Applovin
- Add the SDK Key, add the following
<meta-data>
element to your AndroidManifest.xml, inside the<application>
element:
- TPV7.3.0.1 began to support the server to deliver the SDK KEY.
<meta-data
android:name="applovin.sdk.key"
android:value="YOUR_SDK_KEY_HERE" />
(3)Smaato
If your application targets Android 5.0 (API level 21) or higher, then you need to add the following line to your application AndroidManifest.xml file:
<uses-feature android:name="android.hardware.location.network" />
(4)GDT
- If the targetSdkVersion >= 24 when you package the App, in order to allow the SDK to download and install App-like advertisements normally. Need to add
provider
tag - The gdt_file_path.xml file Tencent side writes directly into the GDT SDK. If the resource package is not successfully imported, an error will be reported that the file cannot be found.
<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>
(5)Mintegral CN
- 中国大陆流量版本必需,海外版本可以不添加
- 需要在AndroidManifest.xml中添加
provider
标签 - 其中
mb_provider_paths
文件TP直接写入MTG adapter中。如果没成功引入,会报错找不到该文件。 - xml找不到,开发者需自行检查,项目中是否正常引入MTG adapter。
<provider
android:name="com.mbridge.msdk.foundation.tools.MBFileProvider"
android:authorities="${applicationId}.mbFileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/mb_provider_paths"/>
</provider>
(6)头条穿山甲CSJ
- 需要在AndroidManifest.xml中添加
provider
标签 - 其中
file_paths .xml
文件TP直接写入toutiao adapter中。如果没成功引入,会报错找不到该文件。 - xml找不到,开发者需自行检查,项目中是否正常引入toutiao adapter。
<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/file_paths" />
</provider>
(7)国内Sigmob
- 其中
sigmob_provider_paths.xml
文件TP直接写入sigmob adapter中。如果没成功引入,会报错找不到该文件。 - xml找不到,开发者需自行检查,项目中是否正常引入sigmob adapter。
<!-- targetSDKVersion >= 24时才需要添加这个provider。
provider的authorities属性的值为${applicationId}.sigprovider -->
<provider
android:name="com.sigmob.sdk.SigmobFileProvider"
android:authorities="${applicationId}.sigprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/sigmob_provider_paths"/>
</provider>
(8)国内米盟Mimo
-
其中
file_paths.xml
文件TP直接写入mimo adapter中。如果没成功引入,会报错找不到该文件。 -
xml找不到,开发者需自行检查,项目中是否正常引入mimo adapter。
-
AndroidX 项目需要添加
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
- Android Support 项目需要添加
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
Android 9以上适配
注意:如果缺少该配置,可能会导致广告图片显示不出来
网络安全配置
Google为保证用户数据和设备的安全,针对Android 系统(Android P) 的应用程序要求默认使用加密连接。在Android P系统的设备上,如果应用使用的是非加密的明文流量的http网络请求,则会导致该应用无法进行网络请求,https则不会受影响;故开发者需要更改 App 的网络安全配置以允许此类连接。
更多了解,请看Google官网文档网络安全配置。
- 添加网络安全配置文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
</manifest>
- 其中在项目的res/xml文件夹新增network_security_config.xml,内容如下:
项目路径:res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
Apache的兼容
在 Android 6.0 中,SDK移除了对 Apache HTTP 客户端的支持。从 Android 9 开始,该内容库已从 bootclasspath 中移除,且默认情况下应用无法使用它。
更多了解,请看Google官网文档 Apache HTTP 客户端弃用。
<application>
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
</application>
Android 12以上适配
- 集成Admob、IronSource、Fyber上架Google Play市场的应用
- 其中Admob 移动广告 SDK 版本 20.4.0 或更高版本已经默认声明该权限
- 项目target更新到 31 (Android 12) ,则需要许可来读取设备的广告 ID。
- 了解更多请查看Google Advertising ID changes
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
- 集成Tapjoy V12.9.0 (TradPlus V7.7.0.1及以上),该SDK包括play-services-ads v17.1.0。对于Google Play Families Program成员,17.1.0版本 play-services-ads 中包括的AD_ID许可必须删除。
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>
视频广告的硬件加速
- 集成Meta(Facebook)、Mintegral、ChartBoost等视频广告需要启用硬件加速渲染,否则可能会在视频视图中遇到黑屏。
- 将以下属性添加到
<application>
标记以启用整个应用程序的硬件加速
<application
android:hardwareAccelerated="true" >
混淆配置
- 漏添加混淆文件,将导致打Release包时无法拉取到TP广告配置而请求广告失败。
-keep public class com.tradplus.** { *; }
-keep class com.tradplus.ads.** { *; }
资源优化
广告SDK的资源不能被混淆,如果使用第三方的资源优化框架,请配置SDK的资源为白名单,例如:
# 接入原生、原生横幅、原生拼接开屏等广告类型
R.string.tp_*
R.drawable.tp_*
R.layout.tp_*
R.id.tp_*
# 集成交叉推广、adx
R.string.cp_*
R.drawable.cp_*
R.layout.cp_*
R.id.cp_*
# 集成游可赢Klevin
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_*