세상사는 이야기 / 도움이 되었다면 배너 클릭 부탁드려요~ →→→

2019년 1월 29일 화요일

[Unity Android] Unity 2018 - mainTemplate.gradle 정리

[Unity Android] 버전 체크 mainTemplate.gradle 파일

Unity 2018.3 버전에서 사용

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
    repositories {
        if (GradleVersion.current() >= GradleVersion.version("4.2")) {
            jcenter()
            google()
        } else {
            jcenter()
        }
        maven { url "https://maven.google.com/"}
    }


    dependencies {
           // use newer version of the plugin for newer unity/gradle versions
            if (GradleVersion.current() < GradleVersion.version("4.0")) {
                classpath 'com.android.tools.build:gradle:2.1.0'
            } else if (GradleVersion.current() < GradleVersion.version("4.2")) { // Unity 2018.1 : Gradle version 4.0.1
            classpath 'com.android.tools.build:gradle:2.3.3'
            } else {                        // Unity 2018.2 : Gradle version 4.2.1
                classpath 'com.android.tools.build:gradle:3.0.1'
            }
    }
}


allprojects {
    repositories {
        if (GradleVersion.current() >= GradleVersion.version("4.2")) {
            jcenter()
            google()
        } else {
            jcenter()
        }


        maven { url 'https://maven.google.com'}
        flatDir {
            dirs 'libs'
        }
    }
}


apply plugin: 'com.android.application'


dependencies {
    compile 'com.android.support:multidex:1.0.1'


    if (GradleVersion.current() >= GradleVersion.version("4.2")) {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
    } else {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }
**DEPS**
}


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


    if (GradleVersion.current() < GradleVersion.version("4.2")) {
        // fix complaint that 3rd party libraries have the same package name
        enforceUniquePackageName false
    }


    defaultConfig {
        minSdkVersion    **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        applicationId '**APPLICATIONID**'
        
        versionCode    **VERSIONCODE**
        versionName    '**VERSIONNAME**'


        // Enabling multidex support.
        multiDexEnabled true


        if (GradleVersion.current() >= GradleVersion.version("4.0")) {
            ndk {
                abiFilters **ABIFILTERS**
            }
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }


    lintOptions {
        abortOnError false
    }


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


**SIGN**
    buildTypes {
          debug {
             minifyEnabled **MINIFY_DEBUG**
            if (GradleVersion.current() >= GradleVersion.version("4.2")) {// > Build-in class shrinker and multidex are not supported yet.
                useProguard **PROGUARD_DEBUG**            
            }
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
              jniDebuggable true
          }
          release {
             minifyEnabled **MINIFY_RELEASE**
             if (GradleVersion.current() >= GradleVersion.version("4.2")) {// > Build-in class shrinker and multidex are not supported yet.
                useProguard **PROGUARD_RELEASE**
            }
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
              **SIGNCONFIG**
          }
    }
**PACKAGING_OPTIONS**
}


**SOURCE_BUILD_SETUP**


댓글 3개:

  1. 안녕하세요 좋은글 잘봤습니다
    몇가지 궁금한게 있어서 여쭤봅니다
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    이런 부분들이 있는데
    compileSdkVersion 26
    buildToolsVersion '25.0.1'

    이런식으로 작성 후 사용하면 되는것인가요??

    답글삭제
  2. Unity 버전에 따라서 위 버전들이 달라져서 따로 설정해 주시면 버전을 올렸을때 빌드가 안될수 있습니다.
    "**XXXX**"는 유니티가(Gradle) 알아서 값을 넣어주는것으로 따로 설정해 주지 않아도 되요

    답글삭제