1
0

More than 1 year has passed since last update.

Unity2018.4 Android対応その2

Last updated at Posted at 2021-12-09

前回はjdk11を差し替えことで問題解決しました、今回はgradleを更新するの解決方法を紹介します。

facebook-loginやline-loginを依存する時は
Target APIはAPI LEVEL 31(Android12)を選択してビルドするとエラーが出ました。

An exception has occurred in the compiler (1.8.0-adoptopenjdk). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)

Gradleを6.1.1へアップデート

ここから6.1.1のバイナリをダウンロード。
zipを解凍

※ unity2018.4.24f1以前
/Applications/Unity/Hub/Editor/2018.4.22f1/PlaybackEngines/AndroidPlayer/Tools/gradle を置き換え。

※ unity2018.4.24f1以後
Preferences > External Tools > Android > Gradle Installed with Unity.でパスを指定します

UnityのPlayerSettingsのPublishing Settings/Build/Custom Gradle Template にチェックを入れる。mainTemplate.gradleを修正

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

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
**BUILD_SCRIPT_DEPS**}
}

Android SDK Build-Toolsは31をアンインストール、30.0.3をインストールします。

gradleOut.aab does not existのエラーが出てます

Android PostProcess task "Exporting project" took 269.852 ms
DisplayProgressbar: Building Gradle project
FileNotFoundException: Temp/gradleOut/build/outputs/bundle/release/gradleOut.aab does not exist

mainTemplate.gradleを修正

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

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        applicationId '**APPLICATIONID**'
        ndk {
            abiFilters **ABIFILTERS**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
        tasks.whenTaskAdded { task ->
            if (task.name.startsWith("bundle")) {
                def renameTaskName = "rename${task.name.capitalize()}Aab"
                def flavor = task.name.substring("bundle".length()).uncapitalize()
                tasks.create(renameTaskName, Copy) {
                    def path = "${buildDir}/outputs/bundle/${flavor}/"
                    from(path)
                    include "gradleOut-${flavor}.aab"
                    destinationDir file("${buildDir}/outputs/bundle/${flavor}/")
                    rename "gradleOut-${flavor}.aab", "gradleOut.aab"
                }

                task.finalizedBy(renameTaskName)
            }
        }
    }
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0