在Android studio中构建Unity项目(有firebase)时出错

时间:2018-04-07 10:15:51

标签: android firebase unity3d gradle

我正在为Android平台开发一个统一项目。我不得不使用gradle(new)方法进行构建,因为字段引用的数量超过了允许的数量。我也在项目中使用firebase和FbSDK。但是,我无法正确构建它。所以,我想到了导出项目并使用Android studio构建它。但是,我在构建项目时遇到错误。错误是

  

找不到包名称'com.google.firebase.unity'的匹配客户。

根据firebase,我需要在gradle文件中添加以下行。

1. Project-level build.gradle (<project>/build.gradle):

buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.2.0'
}
}


2. App-level build.gradle (<project>/<app-module>/build.gradle):

dependencies {
// Add this line
compile 'com.google.firebase:firebase-core:12.0.0'
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

这些是我的gradle文件: 项目/的build.gradle

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

    buildscript {
    repositories {
    jcenter()
    google()
}

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0'
    classpath 'com.google.gms:google-services:3.2.0'
}
}

allprojects {
 repositories {
  flatDir {
    dirs 'libs'
     }
  }
}

apply plugin: 'com.android.application'

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'facebook-android-sdk-4.23.0', ext:'aar')
    compile(name: 'facebook-android-wrapper-7.10.1', ext:'aar')
    compile project(':Firebase')
}

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

defaultConfig {
    multiDexEnabled true
    targetSdkVersion 27
    applicationId 'com.DefaultCompany.Data_Collection'
}

lintOptions {
    abortOnError false
}
signingConfigs { release {
    storeFile file('C:\\Users\\vaish\\.android\\debug.keystore')
    storePassword 'qwerty123'
    keyAlias 'datacollection'
    keyPassword 'qwerty123'
} }

buildTypes {
    debug {
        jniDebuggable true
    }
    release {
        // Set minifyEnabled to true if you want to run ProGuard on your project
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
        signingConfig signingConfigs.release
    }
}


}

项目/火力地堡/的build.gradle

buildscript {
        repositories {
        mavenCentral()
        google()
    }
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0'
}
}

apply plugin: 'android-library'

dependencies {
    compile fileTree(dir: 'bin', include: ['*.jar'])
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.firebase:firebase-core:12.0.0'
}

 android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            //java.srcDirs = ['src']
             res.srcDirs = ['res']
            assets.srcDirs = ['assets']
       }
}

compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
    targetSdkVersion 9
}

lintOptions {
    abortOnError false
}
}
apply plugin: 'com.google.gms.google-services'

错误日志是:

    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':Firebase:processDebugGoogleServices'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: org.gradle.api.GradleException: No matching client found for package name 'com.google.firebase.unity'
        at com.google.gms.googleservices.GoogleServicesTask.action(GoogleServicesTask.java:123)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:780)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:747)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
        ... 32 more

我第一次使用gradle进行构建,对此并不了解。

1 个答案:

答案 0 :(得分:1)

如果你使用 firebase unity插件,你会发现一个可以将google-services.json转换为google-services.xml的python代码。(我想你已经拥有它了强>)

如果您拥有此xml,则无需申请插件:'com.google.gms.google-services'

尝试删除它并重建您的项目我希望它肯定会运行。