Android Setup(deprecated)

Setting up gradle

baseProjectTemplate.gradle :

//Unity 2019.4 or prev
allprojects {
    buildscript {
        ...
        }

        dependencies {            
            classpath 'com.android.tools.build:gradle:3.4.3'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"
            **BUILD_SCRIPT_DEPS**
        }
    }
}
//Unity 2020.3 or higher
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**
        }
    }
}
//Unity 2022.3 higher
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**
}

mainTemplate.gradle :

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

    implementation 'io.github.coolishbee:universalsdk:3.0.x' //Please use the latest version
    implementation 'com.google.code.gson:gson:2.8.5' //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 'io.github.coolishbee:universalsdk:3.0.x' //Please use the latest version
    implementation 'com.google.code.gson:gson:2.8.5' //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 'io.github.coolishbee:universalsdk:3.0.x' //Please use the latest version
    implementation 'com.google.code.gson:gson:2.8.5' //added

**DEPS**}

Resolver usage

For resolver users, please refer to UniversalSDKDependencies.xml

<?xml version="1.0" encoding="utf-8"?>
<dependencies>    
    <androidPackages>
        <androidPackage spec="io.github.coolishbee:universalsdk:3.0.x"/>
        <repositories>
            <repository>https://s01.oss.sonatype.org/content/repositories/releases</repository>
        </repositories>
        <androidPackage spec="com.google.code.gson:gson:2.8.5"/>
        <androidPackage spec="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"/>
    </androidPackages>
</dependencies>

Apply social id to project

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

check-gradle

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