Unity 2020.2.6 Android build aptOptions noCompress property definition error

Viewed 9333

today I tried to build my game for Android with Unity 2020.2.6f1 and it gave the error below;

UnityException: Error mainTemplate.gradle file is using the old aaptOptions noCompress property definition which does not include types defined by unityStreamingAssets constant.

I disabled the Android Resolvers Patch gradle and manifest files it didn't work. I tried to edit the gradle manually with;

aaptOptions {
    noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
    ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}

whatever I do when building the game Unity overrides the gradle, I checked the pre-post build process scripts in the project but none of the ones I check changes the gradle' aaptOptions.

The plugins I have in the project are;

  • Facebook
  • GameAnalytics
  • Adjust

mainTemplate.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }

    dependencies {
        
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

apply plugin: 'com.android.library'
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.installreferrer:installreferrer:1.0'
    **DEPS**
}

android {
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    defaultConfig {
        multiDexEnabled true
        minSdkVersion 19
        targetSdkVersion 29
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
        
    }

    dexOptions {
        preDexLibraries false
        javaMaxHeapSize "4g"
    }

    lintOptions {
        abortOnError false
    }

    packagingOptions {
       exclude  'jsr305_annotations/Jsr305_annotations.gwt.xml'
    }

    aaptOptions {
        noCompress '.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**
    }
    **SIGN**

    buildTypes {
        debug {
            jniDebuggable true
        }
        release {
            minifyEnabled false
            **SIGNCONFIG**
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Thanks in advance.

3 Answers

you should modify like this in the mainTemplate.gradle file :

aaptOptions {
    noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
    ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}

For me what worked was unchecking the "Custom Gradle Template" option for the build inside Player Settings > Publishing Settings.

Edit: Okay it turns out that I can't replicate that anymore and I am not really sure what kind of wizardry allowed it to happen...

On the other hand, I found what caused the issue for me. The problem was caused by one plugin I was using, since I was importing an old version of it and for some reason it kept importing gradle documents and other Android related stuff, which were deprecated.

I fixed it by importing everything from the plugin's Unity Package except the Android folder, all the Editor's gradles and gradle related stuff (I didn't import the Editor folder at all) and the Plugins folder.

Let's try this option. Work like champ.

  • Open file maingradle in Android folder and remove line have string "Proguard" then save file
  • Go to project setting => untick mainGradle and tick again mainGradle, untick gradle properties template and tick it again. Go to Asset option in top => find option force resolve and rebuild again.
Related