facebook twitter hatena line email

「Unity/実機/Android」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(AAB対応)
(MacOSのcatalinaでAndroidでビルドに失敗する不具合対応)
(同じ利用者による、間の29版が非表示)
行58: 行58:
 
  remote No space left on device
 
  remote No space left on device
 
端末内に容量がないので、アプリをいくつか削除する
 
端末内に容量がないので、アプリをいくつか削除する
 +
 +
===UnityEditor.BuildPlayerWindow+BuildMethodExceptionのエラーが出る場合===
 +
*gradleのversionを上げる?
 +
*unityコンソールの上の方に別のエラーがないか確認する。
  
 
==gradleで動かす方法==
 
==gradleで動かす方法==
行157: 行161:
 
#file/build setting/ExportProjectにチェックを入れる
 
#file/build setting/ExportProjectにチェックを入れる
 
#exportボタンを押す
 
#exportボタンを押す
 
===Cannot read packageName AndroidManifest.xmlエラーの場合===
 
manifestにpackage名を登録する
 
<manifest package="jp.co.example.hogehoge"
 
以下略
 
 
buildsystemがinternalだとpackage名を省略できたがGradleだと省略できなかった。
 
 
gradleのPackageNameについて
 
* 2018.1.1f1だとOtherSettings側のPackageNameでなくAndroidManifest.xml側のPackageNameに書いたほうで上書掛かれた。
 
* 2018.3.0f2だとOtherSettings側のPackageNameに記述したものが、AndroidManifest.xml側のPackageNameよりも優先された。
 
  
 
==AndroidManifest.xmlを作成する==
 
==AndroidManifest.xmlを作成する==
行187: 行180:
 
       <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
 
       <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
 
     </activity>
 
     </activity>
     <meta-data android:name="unity.build-id" android:value="05a8f86c-bb43-431c-9b29-a73d7c23160d" />
+
     <meta-data android:name="unity.build-id" android:value="05a8f86c-bb43-431c-9b29-a73d7xxxxxx" />
 
     <meta-data android:name="unity.splash-mode" android:value="0" />
 
     <meta-data android:name="unity.splash-mode" android:value="0" />
 
     <meta-data android:name="unity.splash-enable" android:value="True" />
 
     <meta-data android:name="unity.splash-enable" android:value="True" />
行197: 行190:
 
   <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
 
   <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
 
  </manifest>
 
  </manifest>
 +
===Cannot read packageName AndroidManifest.xmlエラーの場合===
 +
manifestにpackage名を登録する
 +
<manifest package="jp.co.example.hogehoge"
 +
以下略
 +
 +
buildsystemがinternalだとpackage名を省略できたがGradleだと省略できなかった。
 +
 +
gradleのPackageNameについて
 +
* 2018.1.1f1だとOtherSettings側のPackageNameでなくAndroidManifest.xml側のPackageNameに書いたほうで上書掛かれた。
 +
* 2018.3.0f2だとOtherSettings側のPackageNameに記述したものが、AndroidManifest.xml側のPackageNameよりも優先された。(package_nameがなくても追加されると思う(未確認))
 +
* 2019.1.6f1でもOtherSettings側のPackageNameに記述したものが、AndroidManifest.xml側のPackageNameよりも優先された。(package_nameがなくても追加された)
  
 
==multidex必須と出たとき==
 
==multidex必須と出たとき==
行244: 行248:
 
追加すると以下のようなzipが追加される
 
追加すると以下のようなzipが追加される
 
  android-1.40.0-v48.symbols.zip
 
  android-1.40.0-v48.symbols.zip
 +
 +
==="このリリースは Google Play 64 ビット要件に準拠していません。以下の APK または App Bundle は 64 ビットのデバイスで利用できますが、32 ビット向けネイティブ コードしか含まれていません。68。"エラーが出る場合===
 +
unityのbuildのandroid設定でotherSettingのx86のチェックを外す。
 +
 +
https://teratail.com/questions/207173
  
 
==AAB対応==
 
==AAB対応==
行251: 行260:
 
#BuildAppBundleを選択する
 
#BuildAppBundleを選択する
 
https://techblog.kayac.com/unity_advent_calendar_2018_18
 
https://techblog.kayac.com/unity_advent_calendar_2018_18
 +
 +
==android9でhttp通信==
 +
[[Unity/Csharp/Request]] [ショートカット]
 +
 +
==com.android.supportやandroidxが見つからないエラーの場合==
 +
以下のようなgoogle系が見つからない。
 +
com.android.support.constraint:constraint-layout:1.1.2
 +
androidx.constraintlayout:constraintlayout:1.1.3
 +
com.android.support:appcompat-v7:27.1.1
 +
androidx.appcompat:appcompat:1.1.0
 +
 +
Assets/Plugins/Android/mainTemplate.gradle
 +
- classpath 'com.android.tools.build:gradle:2.3.0'
 +
+ classpath 'com.android.tools.build:gradle:3.1.3'
 +
に変えてみるとよい
 +
 +
==com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archivesなエラーの場合==
 +
The number of method references in a .dex file cannot exceed 64K.
 +
 +
multidexの問題かもしれない。
 +
 +
com.android.support:multidexとmultiDexEnabledを追加。
 +
 +
Assets/Plugins/Android/mainTemplate.gradle
 +
<pre>
 +
dependencies {
 +
    implementation fileTree(dir: 'libs', include: ['*.jar'])
 +
    implementation 'com.android.support:multidex:1.0.3'
 +
}
 +
android {
 +
  defaultConfig {
 +
      multiDexEnabled true
 +
  }
 +
}
 +
</pre>
 +
 +
androidxの場合は
 +
implementation 'androidx.multidex:multidex:2.0.1' もあるみたい。
 +
 +
上記で直らなければ、ライブラリが他とかぶってる可能性がある、近くにライブラリが表示されてるはず。
 +
 +
D8: Program type already present: com.google.android.gms.common.api.internal.zzb
 +
があり、
 +
<androidPackage spec="com.google.android.gms:play-services-location:16.0.0">
 +
<androidPackage spec="com.google.android.gms:play-services-gcm:16.0.0">
 +
あたりのversionを統一するか一つ以外の不要なものを削除すると直る。
 +
 +
==Failed to process resources, see aapt output above for detailsなエラーの場合==
 +
エラーの詳細続き
 +
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
 +
基本は上の項目と同じで
 +
Plugins/Android/mainTemplate.gradle
 +
を確認して被ってるものがないか確認。
 +
AndroidのTargetAPILevelなどを29とか最新に変えてみる。
 +
 +
==INSTALL_FAILED_NO_MATCHING_ABISエラー==
 +
Unityの2019.2.12f1で以下エラーが発生した。
 +
CommandInvokationFailure: Unable to install APK to device. Please make sure the Android SDK is installed and is properly configured in the
 +
Editor. See the Console for more details.
 +
Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract
 +
native libraries, res=-113]
 +
シミュレータで起動してるosがABIがx86だったためで、build環境にx86の非推奨にチェックを入れてなかったので出てた。

2020年4月16日 (木) 19:49時点における版

目次

Android実機で動かす

  • File/BuildSettingsを選択
  • Androidを選択
  • OpenDownloadPageからプレイヤーをDL
  • Unityを一度再起動
  • Unity/Preference/ExternalTools/Android/SDK・JDK・NDKのpathを入れる
SDK=/Users/[user]/Library/Android/sdk
JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/bin/java # 確認 $ locate jdk | grep bin/java$
NDK=/Users/[user]/Library/Android/sdk/ndk-bundle
  • PlayerSettingsを選択
  • Inspector/端末マーク/OtherSetting
  • Bundle Identifierの"com.company.ProjectName"を適宜変更する(デフォから変えないとbuild時にエラーとなる)
  • buildボタンを押しapkを作成する
  • build&runボタンを押しandroidで動作させる。
  • 縦向き・横向きで確認する

向きを固定

  • File/BuildSettings
  • OriantationをAutoRotationからportrait(縦)へ

ビルドエラー

Bundle Identifier has not been set up correctly

  • 上記のBundle Identifierがデフォルトの"com.company.ProjectName"だと起こるエラー。適宜変更する

NDK 13.1.3345770 is incompatible with IL2CPP. IL2CPP requires r10e (64-bit).エラーとなる場合

  1. NDK欄隣のDownloadボタンを押し、
  2. android-ndk-r10e-darwin-x86_64.binをDownload
  3. 適当な場所に移動し、NDKのpathへ入力する

Unable to list target platforms. Please make sure the android sdk path is correct. See the Console for details.エラーの場合

最新の Android Studio に付属している SDK Tools がまずいようなので、25バージョンを使うように

https://dl.google.com/android/repository/tools_r25.2.5-macosx.zip

~/Library/Android/sdk/toolsを差し替える

AndroidBuildエラー(2018.3.0f2で発生)

Android SDK is outdated
SDK Build Tools version 28.0.0 < 28.0.3.
Note: when building with Gradle, "Use Highest Installed" option will update SDK Build Tools as well.

Use Highest Installedボタンを選択するとbuildできた。

transformClassesWithMultidexlistForReleaseエラー

com.android.build.api.transform.TransformException: Error while generating the main dex list.

Assets/Plugins/Android/mainTemplate.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:multidex:1.0.3'
}

classpath 'com.android.tools.build:gradle:3.2.0'が2系じゃなくて3系の場合は、 implementationがcompileになってる可能性があるので治す。

remote No space left on deviceエラー

CommandInvokationFailure: Unable to install APK to device. Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details. 
remote No space left on device

端末内に容量がないので、アプリをいくつか削除する

UnityEditor.BuildPlayerWindow+BuildMethodExceptionのエラーが出る場合

  • gradleのversionを上げる?
  • unityコンソールの上の方に別のエラーがないか確認する。

gradleで動かす方法

  1. file/build setting/build systemを"internal"から"gradle"にする

gradleでプロガード設定のないlibsを動かす方法

  1. file/build setting/build systemを"internal"から"gradle"にする
  2. file/build setting/PlayerSetting/PublisingSetting/minifyのreleaseを"progurad"から"none"に変更する

gradleのカスタムファイルを作る

  1. file/build setting/PlayerSetting/PublisingSetting/Build/CustomGradleTemplateにチェックを入れる
  2. Assets/Plugins/AndroidにmainTemplate.gradleができる

2018.3.0f2のmainTemplate.gradleのテンプレ

buildscript {
    repositories {
        google()
        jcenter()
    }

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

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

apply plugin: 'com.android.application'
**APPLY_PLUGINS**

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
**DEPS**}
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**'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]
    }**SIGN**
    buildTypes {
        debug {
            minifyEnabled **MINIFY_DEBUG**
            useProguard **PROGUARD_DEBUG**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
            jniDebuggable true
        }
        release {
            minifyEnabled **MINIFY_RELEASE**
            useProguard **PROGUARD_RELEASE**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
        }
    }**PACKAGING_OPTIONS****SPLITS**
**BUILT_APK_LOCATION**
    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = true
        }
    }
}**SPLITS_VERSION_CODE****REPOSITORIES****SOURCE_BUILD_SETUP**

AndroidStudio用ファイルを出力する

  1. file/build setting/ExportProjectにチェックを入れる
  2. exportボタンを押す

AndroidManifest.xmlを作成する

  1. 一度ビルドするとTemp/StagingArea/AndroidManifest.xmlができる。
  2. それをAssets/Plugins/Androidの下にコピー

参考:https://qiita.com/peroon/items/ba55d583a68c58f0faa5

Unity2018.1.1f1で作成された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" android:installLocation="preferExternal">
 <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
 <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:isGame="true" android:banner="@drawable/app_banner">
   <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
     <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
       <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
     </intent-filter>
     <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
   </activity>
   <meta-data android:name="unity.build-id" android:value="05a8f86c-bb43-431c-9b29-a73d7xxxxxx" />
   <meta-data android:name="unity.splash-mode" android:value="0" />
   <meta-data android:name="unity.splash-enable" android:value="True" />
 </application>
 <uses-feature android:glEsVersion="0x00020000" />
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
 <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
 <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

Cannot read packageName AndroidManifest.xmlエラーの場合

manifestにpackage名を登録する

<manifest package="jp.co.example.hogehoge"
以下略

buildsystemがinternalだとpackage名を省略できたがGradleだと省略できなかった。

gradleのPackageNameについて

  • 2018.1.1f1だとOtherSettings側のPackageNameでなくAndroidManifest.xml側のPackageNameに書いたほうで上書掛かれた。
  • 2018.3.0f2だとOtherSettings側のPackageNameに記述したものが、AndroidManifest.xml側のPackageNameよりも優先された。(package_nameがなくても追加されると思う(未確認))
  • 2019.1.6f1でもOtherSettings側のPackageNameに記述したものが、AndroidManifest.xml側のPackageNameよりも優先された。(package_nameがなくても追加された)

multidex必須と出たとき

Execution failed for task ':transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: 
java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files

multidexを追加するかライブラリ数orライブラリメソッド数を減らす

multidexのバージョンが存在しないと出たとき

A problem occurred configuring root project 'gradleOut'.
> Could not resolve all dependencies for configuration ':_debugApkCopy'.
   > Could not find com.android.support:multidex:1.0.3.

multidexが適切にインストールされているか確認する

ls ~/Library/Android/sdk/extras/android/m2repository/com/android/support/multidex/1.0.3/multidex-1.0.3.jar

なければsdktoolのandroidSupportRegistryをアンインストールしてインストールする。

androidのbackキー

if (Application.platform == RuntimePlatform.Android)
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
    }
}

64bit対応

buildSetting/Android/Configures

  1. scriptingBackendをmonoからIL2CPPへ
  2. ARM64にチェック

上記設定時の設定ファイル差分 ProjectSettings/ProjectSettings.asset

-  AndroidTargetArchitectures: 5
+  AndroidTargetArchitectures: 7
-  scriptingBackend: {}
+  scriptingBackend:
+    Android: 1

公式androidサポート:https://developer.android.com/distribute/best-practices/develop/64-bit#test_your_app_on_64-bit_hardware

  1. build時にndkが存在しない時はndkのDLダイアログがでるのでDLする
  2. DLダイアログが出ない場合はこちらから(https://developer.android.com/ndk/downloads/older_releases.html?hl=ja)
  3. android-ndk-r16b-darwin-x86_64.zip
  4. 解凍して設置して、ndkを指定する

追加すると以下のようなzipが追加される

android-1.40.0-v48.symbols.zip

"このリリースは Google Play 64 ビット要件に準拠していません。以下の APK または App Bundle は 64 ビットのデバイスで利用できますが、32 ビット向けネイティブ コードしか含まれていません。68。"エラーが出る場合

unityのbuildのandroid設定でotherSettingのx86のチェックを外す。

https://teratail.com/questions/207173

AAB対応

  • インストール後のアプリサイズを小さくするもの
  • Unity2018.3ベータから使える
  1. BuildSettingのAndroidでGradleを選択し、
  2. BuildAppBundleを選択する

https://techblog.kayac.com/unity_advent_calendar_2018_18

android9でhttp通信

Unity/Csharp/Request [ショートカット]

com.android.supportやandroidxが見つからないエラーの場合

以下のようなgoogle系が見つからない。

com.android.support.constraint:constraint-layout:1.1.2
androidx.constraintlayout:constraintlayout:1.1.3
com.android.support:appcompat-v7:27.1.1
androidx.appcompat:appcompat:1.1.0

Assets/Plugins/Android/mainTemplate.gradle

- classpath 'com.android.tools.build:gradle:2.3.0'
+ classpath 'com.android.tools.build:gradle:3.1.3'

に変えてみるとよい

com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archivesなエラーの場合

The number of method references in a .dex file cannot exceed 64K.

multidexの問題かもしれない。

com.android.support:multidexとmultiDexEnabledを追加。

Assets/Plugins/Android/mainTemplate.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:multidex:1.0.3'
}
android {
   defaultConfig {
       multiDexEnabled true
   }
}

androidxの場合は

implementation 'androidx.multidex:multidex:2.0.1' もあるみたい。

上記で直らなければ、ライブラリが他とかぶってる可能性がある、近くにライブラリが表示されてるはず。

D8: Program type already present: com.google.android.gms.common.api.internal.zzb

があり、

<androidPackage spec="com.google.android.gms:play-services-location:16.0.0">
<androidPackage spec="com.google.android.gms:play-services-gcm:16.0.0">

あたりのversionを統一するか一つ以外の不要なものを削除すると直る。

Failed to process resources, see aapt output above for detailsなエラーの場合

エラーの詳細続き

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

基本は上の項目と同じで

Plugins/Android/mainTemplate.gradle

を確認して被ってるものがないか確認。 AndroidのTargetAPILevelなどを29とか最新に変えてみる。

INSTALL_FAILED_NO_MATCHING_ABISエラー

Unityの2019.2.12f1で以下エラーが発生した。

CommandInvokationFailure: Unable to install APK to device. Please make sure the Android SDK is installed and is properly configured in the 
Editor. See the Console for more details.
Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract
native libraries, res=-113]

シミュレータで起動してるosがABIがx86だったためで、build環境にx86の非推奨にチェックを入れてなかったので出てた。