5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UnityでAdMobやFirebaseを入れた時のgradleファイルを晒す

Last updated at Posted at 2019-05-02

はじめに

UnityのAndroidビルド時に巻き起こる謎のビルドエラー
だいたいはライブラリの不足や競合だったりするのですが、エラーメッセージが分かりにくい為に解決するのに時間がかかるんですよねー。
ので、自分がビルド通った時のgradleファイルを晒して少しでも参考になればと...
(自分自身Androidやgradleについてあまり詳しくないので、ちょっとずつ加筆修正していくと思います)

実装環境

  • Unity 2019.1.0f2
  • gradle 3.2.0

使用ライブラリ

  • Firebase Analytics
  • Firebase Remote Config
  • AdMob
  • nend(AdMob Mediation)
  • AppLovin(AdMob Mediation)

gradleファイル

mainTemplate.gradle
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

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'])

    // AndroidSupport
    compile group: 'com.android.support', name: 'customtabs', version: '26.1.0'
    compile group: 'com.android.support', name: 'support-annotations', version: '26.1.0'
    compile group: 'com.android.support', name: 'support-compat', version: '26.1.0'
    compile group: 'com.android.support', name: 'support-core-ui', version: '26.1.0'
    compile group: 'com.android.support', name: 'support-core-utils', version: '26.1.0'
    compile group: 'com.android.support', name: 'support-fragment', version: '26.1.0'
    compile group: 'com.android.support', name: 'support-media-compat', version: '26.1.0'
    compile group: 'com.android.support', name: 'support-v4', version: '26.1.0'
    compile group: 'com.android.support', name: 'recyclerview-v7', version: '26.1.0'
    compile group: 'com.android.support', name: 'appcompat-v7', version: '26.1.0'
    compile group: 'com.android.support', name: 'cardview-v7', version: '26.1.0'
    compile group: 'com.android.support.constraint', name: 'constraint-layout-solver', version: '1.1.3'
    compile group: 'com.android.support.constraint', name: 'constraint-layout', version: '1.1.3'

    // gms
    compile group: 'com.google.android.gms', name: 'play-services-ads', version: '17.2.0'
    compile group: 'com.google.android.gms', name: 'play-services-ads-base', version: '17.2.0'
    compile group: 'com.google.android.gms', name: 'play-services-ads-identifier', version: '16.0.0'
    compile group: 'com.google.android.gms', name: 'play-services-ads-lite', version: '17.2.0'
    compile group: 'com.google.android.gms', name: 'play-services-base', version: '16.0.1'
    compile group: 'com.google.android.gms', name: 'play-services-basement', version: '16.2.0'
    compile group: 'com.google.android.gms', name: 'play-services-gass', version: '17.2.0'
    compile group: 'com.google.android.gms', name: 'play-services-measurement', version: '16.4.0'
    compile group: 'com.google.android.gms', name: 'play-services-measurement-api', version: '16.4.0'
    compile group: 'com.google.android.gms', name: 'play-services-measurement-base', version: '16.4.0'
    compile group: 'com.google.android.gms', name: 'play-services-measurement-impl', version: '16.4.0'
    compile group: 'com.google.android.gms', name: 'play-services-measurement-sdk', version: '16.4.0'
    compile group: 'com.google.android.gms', name: 'play-services-measurement-sdk-api', version: '16.4.0'
    compile group: 'com.google.android.gms', name: 'play-services-stats', version: '16.0.1'
    compile group: 'com.google.android.gms', name: 'play-services-tasks', version: '16.0.1'
    
    // Firebase
    compile group: 'com.google.firebase', name: 'firebase-abt', version: '17.1.0'
    compile group: 'com.google.firebase', name: 'firebase-analytics', version: '16.4.0'
    compile group: 'com.google.firebase', name: 'firebase-common', version: '16.1.0'
    compile group: 'com.google.firebase', name: 'firebase-config', version: '16.4.1'
    compile group: 'com.google.firebase', name: 'firebase-core', version: '16.0.8'
    compile group: 'com.google.firebase', name: 'firebase-iid', version: '17.1.0'
    compile group: 'com.google.firebase', name: 'firebase-iid-interop', version: '16.0.1'
    compile group: 'com.google.firebase', name: 'firebase-measurement-connector', version: '17.0.1'
    
    // Other
    compile 'com.google.ads.mediation:nend:5.1.0.1'
    compile 'com.applovin:applovin-sdk:+'
    compile group: 'com.google.auto.value', name: 'auto-value-annotations', version: '1.6.3'
    
    // internal
    compile(name: 'com.google.firebase.firebase-app-unity-5.6.0', ext: 'aar')
    compile(name: 'com.google.firebase.firebase-config-unity-5.6.0', ext: 'aar')
    
**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**

補足

  • gradleへ記載するライブラリ名は https://mvnrepository.com/ で調べました
  • 現在のSDKのバージョンに合わせる必要があります(新しければいいという訳ではないので注意を)
  • // internal の項目のライブラリはファイルをダウンロードしておく必要があります。それ以外はライブラリ競合を起こすので削除 or Androidのビルド対象から外してください
  • AdMobやFirebaseのUnitySDKインポート時に Play Services Resolverがインストールされ、ライブラリが自動的にインポートされます。これはgradleのライブラリと競合を起こすので、以下の手順で自動インポートを解除する必要があります
  1. Settingsへ遷移
    スクリーンショット 2019-05-02 13.12.26.png

  2. Enable Auto-Resolutionのチェックを外しOK
    スクリーンショット 2019-05-02 13.12.37.png

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?