使用 gradle 实验性 android 模型插件构建 Ndk 导致 java.lang.IllegalStateException:名称为 [DEFAULT] 的 FirebaseApp 不存在。
Ndk build with gradle experimental android model plugin causes java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
我尝试 assemble NDK 应用程序与 Firebase 云消息传递使用 android 模型插件和 gradle-experimental。当我打电话给
FirebaseInstanceId.getInstance().getToken()
应用程序调用
java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
如果我从 com.android.model.application 插件切换到 com.android.application 插件,那么一切正常,但不幸的是我需要使用 Cloud Messaging 构建 ndk 项目。你知道如何解决这个问题吗?
Gradle 文件:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 24
buildToolsVersion = "24.0.2"
/* defaultConfig {
applicationId = "com.myapppackage.myappname"
minSdkVersion.apiLevel = 14
targetSdkVersion.apiLevel = 24
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}*/
defaultConfig {
applicationId = "com.myapppackage.myappname"
}
buildTypes {
release {
minifyEnabled = true
useProguard = true
proguardFiles.add(file('proguard-rules.pro'))
ndk.with {
debuggable = false
}
}
debug {
minifyEnabled = true
useProguard = true
debuggable = true
proguardFiles.add(file('proguard-rules.pro'))
ndk.with {
debuggable = false
}
}
}
compileOptions.with {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
ndk {
platformVersion = "14"
moduleName = "testndk"
toolchain = "clang"
ldLibs.add("log")
}
sources {
main {
jni {
source {
srcDirs.removeAll()
srcDirs.add('src/main/jni/netguard')
}
exportedHeaders {
}
}
}
}
productFlavors {
create("all") {
versionName = "1.00"
minSdkVersion.apiLevel = 14
targetSdkVersion.apiLevel = 24
versionCode = 100
archivesBaseName = "MyAppName-v$versionName"
}
create("lollipop-and-later") {
versionName = "1.00"
minSdkVersion.apiLevel = 20
targetSdkVersion.apiLevel = 24
versionCode = 100
archivesBaseName = "MyAppName-v$versionName"
}
create("kitkat-and-earlier") {
versionName = "1.00"
minSdkVersion.apiLevel = 14
maxSdkVersion = 19
targetSdkVersion.apiLevel = 24
versionCode = 100
archivesBaseName = "MyAppName-v$versionName"
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-ads:9.4.0'
testCompile 'junit:junit:4.12'
}
和proguard-rules.pro文件:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-dontobfuscate
-dontoptimize
-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v4.**
-keep public class com.google.android.gms.** {*;}
-dontwarn com.google.android.gms.**
-keep public class com.google.firebase.** {*;}
-dontwarn com.google.firebase.**
在 gradle-experimental 产生 IllegalStateException(名称为 [DEFAULT] 的 FirebaseApp 不存在)时构建此类应用程序的解决方案是构建实验性本机模块作为库并在稳定 gradle 这个例子的模块:
我尝试 assemble NDK 应用程序与 Firebase 云消息传递使用 android 模型插件和 gradle-experimental。当我打电话给
FirebaseInstanceId.getInstance().getToken()
应用程序调用
java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
如果我从 com.android.model.application 插件切换到 com.android.application 插件,那么一切正常,但不幸的是我需要使用 Cloud Messaging 构建 ndk 项目。你知道如何解决这个问题吗? Gradle 文件:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 24
buildToolsVersion = "24.0.2"
/* defaultConfig {
applicationId = "com.myapppackage.myappname"
minSdkVersion.apiLevel = 14
targetSdkVersion.apiLevel = 24
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}*/
defaultConfig {
applicationId = "com.myapppackage.myappname"
}
buildTypes {
release {
minifyEnabled = true
useProguard = true
proguardFiles.add(file('proguard-rules.pro'))
ndk.with {
debuggable = false
}
}
debug {
minifyEnabled = true
useProguard = true
debuggable = true
proguardFiles.add(file('proguard-rules.pro'))
ndk.with {
debuggable = false
}
}
}
compileOptions.with {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
ndk {
platformVersion = "14"
moduleName = "testndk"
toolchain = "clang"
ldLibs.add("log")
}
sources {
main {
jni {
source {
srcDirs.removeAll()
srcDirs.add('src/main/jni/netguard')
}
exportedHeaders {
}
}
}
}
productFlavors {
create("all") {
versionName = "1.00"
minSdkVersion.apiLevel = 14
targetSdkVersion.apiLevel = 24
versionCode = 100
archivesBaseName = "MyAppName-v$versionName"
}
create("lollipop-and-later") {
versionName = "1.00"
minSdkVersion.apiLevel = 20
targetSdkVersion.apiLevel = 24
versionCode = 100
archivesBaseName = "MyAppName-v$versionName"
}
create("kitkat-and-earlier") {
versionName = "1.00"
minSdkVersion.apiLevel = 14
maxSdkVersion = 19
targetSdkVersion.apiLevel = 24
versionCode = 100
archivesBaseName = "MyAppName-v$versionName"
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-ads:9.4.0'
testCompile 'junit:junit:4.12'
}
和proguard-rules.pro文件:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-dontobfuscate
-dontoptimize
-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v4.**
-keep public class com.google.android.gms.** {*;}
-dontwarn com.google.android.gms.**
-keep public class com.google.firebase.** {*;}
-dontwarn com.google.firebase.**
在 gradle-experimental 产生 IllegalStateException(名称为 [DEFAULT] 的 FirebaseApp 不存在)时构建此类应用程序的解决方案是构建实验性本机模块作为库并在稳定 gradle 这个例子的模块: