ことの発端は、Google Cloud Messaging (GCM)を実装するために、Google Play Serviceを読み込むようにしたのですが、
https://developers.google.com/cloud-messaging/android/client
実行時に下記のエラーが出て、実行できなくなってしまったのです。
Error:The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
はぁぁ。。。
で、下記のサイトの指示を読みます。
http://developer.android.com/intl/ja/tools/building/multidex.html
かいつまむと、プログラムが大きくなったり、大きなライブラリを読み込んだりしていると、dexが大きくなって、一つのdexではなくなってしまうので、複数のdexを作るようにするんだよ。ということだそうです。
で、AndroidManifest.xmlと、build.gradleを書いてある通りにやったところ、
Gradle DSL method not found multiDexEnabled()
というGradkeのエラーが出て、先に進みません。。。
ググったりしても、Gradleのバージョンが古いんじゃないか?とかそんな話ばかりでして、役に立ちませんでした。
さて、一日明けて、よくよく自分の作ったbuild.gradleを見てみると、
「あっ multiDexEnabled trueの書いてある場所が違ってた…」
というわけで、うまく動いたbuild.gradleを貼っておきます。
//アプリケーションレベルにあるbuil.gradle
apply plugin: 'com.android.application'
repositories {
maven { url 'https://jitpack.io' }
mavenCentral()
}
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "jp.onlineconsultant.proto"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
//エラー時は、ここに multiDexEnabled trueが書かれていた
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// compile 'com.android.support:appcompat-v7:23.1.1'
//osm bonuspackでつけたし
compile 'com.github.MKergall.osmbonuspack:OSMBonusPack:v5.6.1'
//greenDAOをつけたし
compile 'de.greenrobot:greendao:2.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
//gcm のためにつけたし
compile 'com.google.android.gms:play-services:8.4.0'
//compile 'com.google.android.gms:play-services-gcm:8.4.0'
//Building Apps with Over 65K Methods 対応
//http://developer.android.com/intl/ja/tools/building/multidex.html
compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
//プロジェクトのTOPレベルにあるbuild.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha9'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
// classpath 'com.google.gms:google-services:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
