Android Setup

Setting up gradle

baseProjectTemplate.gradle :

//gradle version 6.1.1
//2021.2.0b4 - 2021.3.36f1
//2022.2.0a1 - 2022.2.0a17
allprojects {
    buildscript {
        ...
        }

        dependencies {            
            classpath 'com.android.tools.build:gradle:4.0.1'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
            **BUILD_SCRIPT_DEPS**
        }
    }
}
//gradle version 6.7.1
//2021.3.37f1 - 2021.3.40f1
allprojects {
    buildscript {
        ...
        }

        dependencies {            
            classpath 'com.android.tools.build:gradle:4.2.2'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
            **BUILD_SCRIPT_DEPS**
        }
    }
}
//gradle version 7.2
//2022.2.0a18 - 2022.3.37f1
plugins {
    id 'com.android.application' version '7.1.2' apply false
    id 'com.android.library' version '7.1.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.3.72' apply false
    **BUILD_SCRIPT_DEPS**
}
//gradle version 7.5.1
//2021.3.41f1+
//2022.3.38f1+
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.5.20' apply false
    **BUILD_SCRIPT_DEPS**
}

mainTemplate.gradle :

//Unity 2019.4 or prev
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.github.coolishbee:universal-sdk-android:3.0.x' //Please use the latest version
    implementation 'com.google.code.gson:gson:2.8.9' //added
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11" //added

**DEPS**}
//Unity 2020.3 or higher
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.github.coolishbee:universal-sdk-android:3.0.x' //Please use the latest version
    implementation 'com.google.code.gson:gson:2.8.9' //added
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61" //added

**DEPS**}
//Unity 2022.3 higher
apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android' //added
**APPLY_PLUGINS**

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.github.coolishbee:universal-sdk-android:3.0.x' //Please use the latest version
    implementation 'com.google.code.gson:gson:2.8.9' //added

**DEPS**}

settingsTemplate.gradle :

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        **ARTIFACTORYREPOSITORY**
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' } //added
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
    }
}

Resolver usage

For resolver users, please refer to UniversalSDKDependencies.xml

<?xml version="1.0" encoding="utf-8"?>
<dependencies>    
    <androidPackages>
        <androidPackage spec="com.github.coolishbee:universal-sdk-android:3.x.x"/>
        <androidPackage spec="com.google.code.gson:gson:2.8.9"/>
    </androidPackages>
</dependencies>

Apply social id to project

Please edit your Assets/Plugins/Android/launcherTemplate.gradle Activate the checkbox to create a file.

Insert the line resValue. If you are not sure, please refer to the Demo.

launcherTemplate.gradle :

dependencies {
    implementation project(':unityLibrary')
    implementation 'androidx.multidex:multidex:2.0.1' //added
    ...
    }
android {
    ...
    defaultConfig {
        ...
        multiDexEnabled true //added

        resValue("string", "facebook_app_id", "com.your.app.id.here")
        resValue("string", "facebook_client_token", "com.your.client.token.here")
        resValue("string", "google_web_client_id", "com.your.client.id.here")
        resValue("string", "apple_client_id", "com.your.service.id.here")
        resValue("string", "redirect_url", "your.return.url.here")
    }
    ...

AndroidX Use

gradleTemplate.properties :

...
android.useAndroidX=true
android.enableJetifier=true

Proguard settings

  • Obfuscating with Proguard when building

  • Project Settings > Player > Publishing Settings > Minify R8 enabled

If you're using Proguard, add the following to the proguard-user.txt file.

-kepp class com.universal.sdk.unitywrapper.** {*;}
-keep class io.github.coolishbee.** { *; }

Last updated