Skip to main content

Android

Editor 2019 and above version import#

Step 1: In Project Setting, check the ticked part in the figure below to generate the files required for Android compilation.#

Step 2: Introduce Gradle#

(1)baseProjectTemplate.gradle Introduce the required Maven library into the file, and the reference of the Maven library shall be subject to the code generated by the packaging platform#

Example

  • Developers need to confirm that the integrated SDK is correctly added to the project according to SDK DownLoad Platform.

  • For example: to access the IronSource SDK, developers need to check the IronSource advertising platform for the packaging platform, and then click to generate code.

  • Copy the repository in the Gradle reference repositories to baseProjectTemplate.gradle the file. See the sample code below for the specific location.
allprojects {
buildscript {
repositories {**ARTIFACTORYREPOSITORY**
// TradPlus SDK maven library
mavenCentral()
google()
// IronSource maven library
maven { url 'https://android-sdk.is.com/' }
jcenter()
}
}
repositories {**ARTIFACTORYREPOSITORY**
// TradPlus SDK maven library
mavenCentral()
google()
// IronSource maven library
maven { url 'https://android-sdk.is.com/' }
jcenter()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}

(2)Configure Gradle mainTemplate.gradle and advertising platform in the file#

Example

  • Copy the Gradle dependencies in the Gradle reference dependencies to mainTemplate.gradle the file. See the sample code below for the specific location.

def tradplus_version = "10.3.0.1"
dependencies {
// noinspection GradleCompatible
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
// TradPlus SDK
implementation "com.tradplusad:tradplus:${tradplus_version}"
// IronSource SDK
implementation 'com.ironsource.sdk:mediationsdk:7.5.1'
implementation "com.tradplusad:tradplus-ironsource:10.${tradplus_version}"
implementation 'com.google.android.gms:play-services-appset:16.0.0'
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
implementation 'com.google.android.gms:play-services-basement:17.5.0'
}

Step 3: Configure manifest file#

(1)AndroidManifest.xml#

  • Step 1: Declare permissions. Development can add permissions according to the access platform.
  • Step 2: Apache Compatibility
  • Step 3: Configure the statement and develop the code generated according to SDK DownLoad Platform to add it (there are screenshots below)
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<!--Step 1: Declare permissions-->
<!-- TG Domestic and Pangolin CSJ Domestic 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 to avoid placing wrong advertisements -->
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
<!-- Pangolin CSJ domestic necessary permissions to solve security risk vulnerabilities. Sending and registering broadcast events requires calling an interface with delivery permissions -->
<permission
android:name="${applicationId}.openadsdk.permission.TT_PANGOLIN"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.openadsdk.permission.TT_PANGOLIN" />
<!--Pangolin CSJ domestic, Pangle V45 or below, please be sure to add it, otherwise the screen will be black -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Android 12 or above, agree to obtain Android Advertiser Identifier -->
<uses-permission android:name="android.permission.AD_ID" />
<application
>
<!-- Step 2: Apache compatibility -->
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<!--Step 3: Configuration statement (the meta-data and provider generated by the packaging platform are added here)-->
<!-- Add Google 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"/>
</application>
</manifest>
  • For example: SDK DownLoad Platform chooses to access Tencent Youlianghui. The AndroidManifest.xml part of the manifest file will generate the providers required by Tencent Youlianghui . Developers can add them directly according to the third step of the sample code.

(2)LauncherManifest.xml#

  • Step 1: Add hardware acceleration for video ads
  • Step 2: Add Network Security Profile
<manifest
...
<application android:label="@string/app_name"
android:icon="@mipmap/app_icon"
<!-- The first step: Hardware acceleration of video ads Meta, MTG, ChartBoost, Adx and other video ads need to start hardware accelerated rendering -->
android:hardwareAccelerated="true"
android:supportsRtl="true"
<!-- AndroidV9.2 is written into the SDK, no configuration is required; projects upgraded from older versions will report errors because the configuration has been added to the manifest file, just delete the configuration -->
<!-- Step 2: Add network security configuration file: network_security_config see below -->
android:networkSecurityConfig="@xml/network_security_config"/>
</manifest>
  • Add network_security_config.xml in the Assets\Plugins\Android\res\xml folder of the project, with the following content:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config
cleartextTrafficPermitted="true">
<domain includeSubdomains="true">127.0.0.1</domain>
</domain-config>
</network-security-config>

Step 4: AndroidX configuration#

  • The AndroidX project needs to be added, and the Support project can be ignored directly.
  • Add configuration in the above file gradleTemplate.properties
android.enableJetifier=true
android.useAndroidX=true

Step 5: Confusing configuration#

  • Add obfuscation configuration in the file proguard-user.txt above
  • After minifyEnabled is turned on, TP-related classes and methods can be found normally, otherwise the release package request advertisement will fail.
-keep public class com.tradplus.** { *; }
-keep class com.tradplus.ads.** { *; }

Step 6: Resource Optimization#

The resources of the advertising SDK cannot be confused. If you use a third-party resource optimization framework, please configure the resources of the SDK as a whitelist, for example:

# Access native, native banner, native splicing screen opening and other advertising types
R.string.tp_*
R.drawable.tp_*
R.layout.tp_*
R.id.tp_*
# Access crosspromotion, adx
R.string.cp_*
R.drawable.cp_*
R.layout.cp_*
R.id.cp_*
# Access 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_*