facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ビルドエラー)
(gradleのカスタムファイルを作る)
行51: 行51:
 
#file/build setting/PlayerSetting/PublisingSetting/Build/CustomGradleTemplateにチェックを入れる
 
#file/build setting/PlayerSetting/PublisingSetting/Build/CustomGradleTemplateにチェックを入れる
 
#Assets/Plugins/AndroidにmainTemplate.gradleができる
 
#Assets/Plugins/AndroidにmainTemplate.gradleができる
 +
 +
2018.3.0f2のテンプレ
 +
<pre>
 +
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**
 +
</pre>
  
 
==AndroidStudio用ファイルを出力する==
 
==AndroidStudio用ファイルを出力する==

2019年1月8日 (火) 17:32時点における版

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できた。

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のテンプレ

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ボタンを押す

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を作成する

  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-a73d7c23160d" />
   <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>

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をアンインストールしてインストールする。