LoginSignup
0
0

More than 1 year has passed since last update.

[Unity] Quest2用ゲームをAndroid Platformでビルドできない

Posted at

概要

ビルドしようと思ってもGradle関連のエラーが直らなかったので備忘録として解決したときの方法を書きます。

環境

Unity 2021.3.17f1
Minimum API Level 29

やったこと

Custom Main Manifestにチェックを入れる

こちらのサイトの方法を行いました。
「UnityPlayerActivity.javaは非推奨のAPIを使用またはオーバーライドしています」が出てビルドできないとき

Project Settings -> Player-> Publishing SettingsにあるCustom Main Manifestにチェックを入れる。
image.png

プロジェクト\Assets\Plugins\AndroidのAndroidManifest.xmlを編集する。

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    xmlns:tools="http://schemas.android.com/tools">
    <application>
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:theme="@style/UnityThemeSelector">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
    </application>
<queries><package android:name="com.google.ar.core" /></queries>
</manifest>

筆者はこれでビルドしてもエラーがでたので以下の手順も行いました。

Gradleをダウンロードする

Gradleのダウンロードページ
筆者は7.5.1のcompleteをダウンロードしました。解凍に時間がかかります。
image.png

Preferences->External Tools->のGradle Installed with Unityの部分をダウンロードしたgradleにする。
image.png

プロジェクト\Assets\Plugins\AndroidにあるbaseProjectTemplate.gradleを編集する。
classpath 'com.android.tools.build:gradle:4.2.0'にする。

baseProjectTemplate.gradle
allprojects {
    buildscript {
        repositories {**ARTIFACTORYREPOSITORY**
            google()
            jcenter()
        }

        dependencies {
            // If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
            // See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html
            // See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
            // To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version
            
            classpath 'com.android.tools.build:gradle:4.2.0'
            **BUILD_SCRIPT_DEPS**
        }
    }

    repositories {**ARTIFACTORYREPOSITORY**
        google()
        jcenter()
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

これでビルドが通るはずと「UnityPlayerActivity.javaは非推奨のAPIを使用またはオーバーライドしています」が出てビルドできないときに書いてありましたがこれでもビルドできなかったのでさらに続きます。

debug.keystoreファイルを削除

.androidにあるdebug.keystoreを削除する。

これでビルドができました。

0
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
0
0