Android Studioを使用してアプリケーションを開発し、いくつかの製品フレーバーを作成してgradleを使用しています。製品フレーバーはgoogle、beta、labです。
Crashlyticsを1つの製品フレーバー(beta)と統合したいだけですが、解決できない問題に直面しています。
現在のbuild.gradleファイルでは、ビルドバリアントbetaDebugおよびbetaReleaseをコンパイルすることができますが、他のバージョンをコンパイルすることはできません。
さらに、betaDebugビルドバリアントを正常に起動した後、Crashlyticsにアプリケーションを認識させることができませんでした。
別のビルドバリアントに切り替えたときに表示されるエラー:
Gradle Running
Failed to complete Gradle exection.
Cause:
Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.10-all.Zip'.
ここに私のbuild.gradleファイルがあります:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'Android'
apply plugin: 'crashlytics'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
Android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
packageName "com.mcarrano.example"
}
buildTypes {
debug {
packageNameSuffix '.debug'
versionNameSuffix '-DEBUG'
}
release {
runProguard true
debuggable false
proguardFile 'proguard-rules.txt'
proguardFile getDefaultProguardFile('proguard-Android-optimize.txt')
}
}
productFlavors {
google {
packageName = Android.defaultConfig.packageName
versionName = Android.defaultConfig.versionName
}
beta {
packageName = Android.defaultConfig.packageName + ".beta"
versionName = Android.defaultConfig.versionName + "-BETA"
}
lab {
packageName = Android.defaultConfig.packageName + ".lab"
versionName = Android.defaultConfig.versionName + "-LAB"
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
Java.srcDirs = ['src/main/Java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
google {
Java.srcDirs = ['src/google/Java']
}
beta {
manifest.srcFile 'src/beta/AndroidManifest.xml'
Java.srcDirs = ['src/beta/Java']
}
lab {
Java.srcDirs = ['src/lab/Java']
}
}
}
dependencies {
compile 'com.Android.support:support-v4:19.0.+'
compile 'com.Android.support:appcompat-v7:19.0.+'
betaCompile 'com.crashlytics.Android:crashlytics:1.+'
}
以下は、アプリケーションのコンパイルに失敗した場合のGradleコンソールです。
Executing tasks: [:example:generateGoogleDebugSources]
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:example:preBuild
:example:preGoogleDebugBuild
:example:checkGoogleDebugManifest
:example:preBetaDebugBuild
:example:preBetaReleaseBuild
:example:preGoogleReleaseBuild
:example:preLabDebugBuild
:example:preLabReleaseBuild
:example:prepareComAndroidSupportAppcompatV71901Library UP-TO-DATE
:example:prepareGoogleDebugDependencies
:example:compileGoogleDebugAidl UP-TO-DATE
:example:compileGoogleDebugRenderscript UP-TO-DATE
:example:generateGoogleDebugBuildConfig UP-TO-DATE
:example:processGoogleDebugManifest UP-TO-DATE
:example:crashlyticsCleanupResourcesGoogleDebug
ERROR - Crashlytics Developer Tools error.
Java.lang.IllegalArgumentException: Invalid API key: null. Check the Crashlytics plugin to make sure that the application has been added successfully! Contact [email protected] for assistance.
at com.crashlytics.tools.Android.DeveloperTools.processProperties(DeveloperTools.Java:439)
at com.crashlytics.tools.Android.DeveloperTools.processArgs(DeveloperTools.Java:325)
at com.crashlytics.tools.Android.DeveloperTools.main(DeveloperTools.Java:285)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:39)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:25)
at Java.lang.reflect.Method.invoke(Method.Java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.Java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.Java:233)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.Java:43)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.Java:88)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.Java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.Java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.Java:116)
at com.crashlytics.tools.gradle.CrashlyticsTaskBuilder.callDevtoolsWrappingRuntimeExceptions(CrashlyticsTaskBuilder.groovy:136)
at com.crashlytics.tools.gradle.CrashlyticsTaskBuilder.this$2$callDevtoolsWrappingRuntimeExceptions(CrashlyticsTaskBuilder.groovy)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:39)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:25)
at Java.lang.reflect.Method.invoke(Method.Java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.Java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.Java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.Java:361)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.Java:877)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.Java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.Java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.Java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.Java:141)
at com.crashlytics.tools.gradle.CrashlyticsTaskBuilder$_crashlyticsCleanupResources_closure2.doCall(CrashlyticsTaskBuilder.groovy:57)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:39)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:25)
at Java.lang.reflect.Method.invoke(Method.Java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.Java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.Java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.Java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.Java:877)
at groovy.lang.Closure.call(Closure.Java:412)
at groovy.lang.Closure.call(Closure.Java:425)
at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.Java:502)
at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.Java:483)
at org.gradle.api.internal.tasks.TaskStatusNagger$1.execute(TaskStatusNagger.Java:77)
at org.gradle.api.internal.tasks.TaskStatusNagger$1.execute(TaskStatusNagger.Java:73)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.Java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.Java:61)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.Java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.Java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.Java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.Java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.Java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.Java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.Java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.Java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.Java:289)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.Java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.Java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.Java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.Java:33)
at org.gradle.internal.Factories$1.create(Factories.Java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.Java:198)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.Java:266)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.Java:135)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.Java:95)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.Java:31)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.Java:86)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.Java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.Java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.Java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.Java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.Java:166)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.Java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.Java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.Java:64)
at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.Java:70)
at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.Java:30)
at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.Java:108)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.Java:35)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.Java:45)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.Java:42)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.Java:24)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.Java:33)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.Java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.Java:71)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.Java:69)
at org.gradle.util.Swapper.swap(Swapper.Java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.Java:69)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.Java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.Java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.Java:45)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.Java:186)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.Java:49)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.Java:36)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.Java:39)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.Java:32)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:125)
at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.Java:51)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.Java:155)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.Java:128)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.Java:116)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.Java:64)
at Java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.Java:895)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:918)
at Java.lang.Thread.run(Thread.Java:695)
usage: com.crashlytics.tools.Android.DeveloperTools
-androidManifest <androidManifestPath> Path to AndroidManifest.xml)
-androidRes <androidResPath> Path to Android resources (res/
folder)
-apiSecret <key> API Secret for the project
-buildEvent Notify Crashlytics that a build
event has occurred
-cleanupResourceFile Remove Crashlytics-generated
resource files
-generateResourceFile Generate Crashlytics-required
resources for the project.
-help Display command help.
-obfuscator <obfuscatorId> Optionally specify an obfuscator
vendor identifier for use with
storeDeobs.
-obVer <obfuscatorVersion> Optionally specify the
obfuscator vendor software
version for use with obfuscator.
-projectPath <path> Path to Android project root
-properties <propertiesarg> Properties file that overrides
the input properties
-quiet Silent command line output
-requireUploadSuccess Throw an exception if the
deobfuscation upload was not
successful
-resourceCheck Check if a resource file already
exists.
-storeDeobs <file> Store the specified
deobfuscation file in
preparation for upload.
-tool <toolarg> Name of the build tool
-uploadDeobs Attempt to upload deobfuscation
file(s) to Crashlytics servers.
-uploadDist <file>
-verbose Verbose command line output
-version <versionarg> Version of the build tool
@ bonnell にメールで私の質問に答えてくれてありがとう。
Crashlyticsに含めたくないビルド/フレーバーにext.enableCrashlytics = falseを追加するだけです。
私の問題を解決する完全な答え:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'Android'
apply plugin: 'crashlytics'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
Android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
packageName "com.mcarrano.example"
}
buildTypes {
debug {
packageNameSuffix '.debug'
versionNameSuffix '-DEBUG'
}
release {
runProguard true
debuggable false
proguardFile 'proguard-rules.txt'
proguardFile getDefaultProguardFile('proguard-Android-optimize.txt')
}
}
productFlavors {
google {
packageName = Android.defaultConfig.packageName
versionName = Android.defaultConfig.versionName
ext.enableCrashlytics = false
}
beta {
packageName = Android.defaultConfig.packageName + ".beta"
versionName = Android.defaultConfig.versionName + "-BETA"
}
lab {
packageName = Android.defaultConfig.packageName + ".lab"
versionName = Android.defaultConfig.versionName + "-LAB"
ext.enableCrashlytics = false
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
Java.srcDirs = ['src/main/Java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
google {
Java.srcDirs = ['src/google/Java']
}
beta {
manifest.srcFile 'src/beta/AndroidManifest.xml'
Java.srcDirs = ['src/beta/Java']
}
lab {
Java.srcDirs = ['src/lab/Java']
}
}
}
dependencies {
compile 'com.Android.support:support-v4:19.0.+'
compile 'com.Android.support:appcompat-v7:19.0.+'
betaCompile 'com.crashlytics.Android:crashlytics:1.+'
}
同様の問題がありました:デバッグビルドでcrashlyticsのレポートをオフにする必要がありました。マイケルの答えは私を助けませんでした:crashlyticsは開始時にアプリケーションを破壊しましたext.enableCrashlytics = false
gradle設定。 Githubのおかげで、実用的なソリューションが見つかりました。
build.gradle:
//...
Android {
buildTypes {
debug {
// enable crashlytics where you need
buildConfigField "boolean", "USE_CRASHLYTICS", "false"
ext.enableCrashlytics = false
}
}
}
// ...
およびapplication class:
@Override
public void onCreate() {
//...
if ( BuildConfig.USE_CRASHLYTICS ) {
Crashlytics.start(this);
}
//...
}
[〜#〜] edit [〜#〜]
slott's comment :によると、Fabricでは次のようなものを使用する必要があります。
Fabric.with(this, new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(!BuildConfig.USE_CRASHLYTICS).build()).build());
この問題を抱えている他の人にとって、私の問題は、CrashlyticsキーがAndroidManifest.xmlファイルで定義されていないことでした。たとえば:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:Android="http://schemas.Android.com/apk/res/Android"
package="com.example.myapp"
Android:versionCode="1"
Android:versionName="1.0">
<uses-permission Android:name="Android.permission.INTERNET"/>
<application Android:label="@string/app_name">
<activity Android:name="MyActivity" Android:label="@string/app_name" />
<meta-data Android:name="com.crashlytics.ApiKey"
Android:value="YOUR_API_KEY"/>
</application>
</manifest>
Crashlyticsを介してビルドを共有する場合。
Fabricプラグインをインストールして登録する必要があります。その後..
**
debug {ext.enableCrashlytics = true}
**
アプリケーションをビルドした後、crashlyticsを介して簡単に共有できます
ありがとう
デバッグビルドのcrashlyticsを停止するには、最初の(開始)アクティビティの初期化コードの後に以下のコードを追加しました
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build(), new Crashlytics());