Upsight logo Back to top

Proguarding

Exporting from Unity

To export your Unity build for use in Android Studio, simply go to build settings, select Gradle under "Build System", check the "Export Project" button and click "Export".

To enable proguard, open the build.gradle in your exported project and replace the buildTypes {...} block with the following:

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license'
        exclude 'LICENSE.txt'
        exclude 'license.txt'
        exclude 'LICENSE'
        exclude 'license'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice'
        exclude 'NOTICE.txt'
        exclude 'notice.txt'
        exclude 'NOTICE'
        exclude 'notice'
        exclude 'META-INF/rxjava.properties'
    }
    buildTypes {
       release {
           minifyEnabled true
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
       }
       debug {
           minifyEnabled true
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
       }
    }

Replace the proguard-rules.txt in your exported project with the one here.

After the project is exported, you can either open the project in Android Studio or build your application directly with gradle with a gradle wrapper:

Note Unity exported projects don't come with a gradle wrapper by default, you will either have to download one separately or open your project in Android Studio to be prompted to download one.

Running with Gradle

If you do not have Gradle already installed on your system, you can either download and install Gradle and generate a wrapper file by following the Gradle Wrapper User Guide. Please note that Unity uses version 2.10 of Gradle.

Alternatively, you can download an Upsight-provided gradlew wrapper from here and unzip into your exported project.

Once you have a wrapper, you can build your application using the gradlew scripts:

On Windows:

.\gradlew.bat assembleDebug #for debug builds
.\gradlew.bat assemble #for release

On OSX:

./gradlew assembleDebug #for debug builds
./gradlew assemble #for release