简体   繁体   English

Unity3D - 使用 Gradle 构建 Android AppBundle 失败

[英]Unity3D - failed Build Android AppBundle using Gradle

currently, my game builds successfully if build using Unity's Internal System.目前,如果使用 Unity 的Internal系统构建,我的游戏构建成功。 Now because I need AppBundle over APK I try to change build system to Gradle like below picture:现在因为我需要通过APK AppBundle ,所以我尝试将构建系统更改为Gradle ,如下图所示:

在此处输入图片说明

However, in Gradle it returns an error.但是,在Gradle它返回一个错误。

Could not find method implementation() for arguments [{name=com.google.android.gms.play-services-drive-11.0.4, ext=aar}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.无法在 org.gradle.api.internal.artifacts 类型的对象上找到参数 [{name=com.google.android.gms.play-services-drive-11.0.4, ext=aar}] 的方法 implementation()。 dsl.dependencies.DefaultDependencyHandler。

Note: I'm using Unity v2017.4.30f1注意:我使用的是 Unity v2017.4.30f1

Any Idea to Solve?有什么解决办法吗?

Thank You谢谢你

Change your mainTemplate.gradle file to something like this:将您的 mainTemplate.gradle 文件更改为如下所示:

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        flatDir {
            dirs 'libs'
        }
    }
}

If this doesn't work, try to find one that works with your unity version, if you updated unity, this file may become incompatible preventing you from making a gradle build.如果这不起作用,请尝试找到一个适用于您的统一版本的文件,如果您更新了统一版本,则此文件可能会变得不兼容,从而阻止您进行 gradle 构建。

An easy fix would be to let unity autogenerate the mainTemplate.gradle file for you, and then applying your changes on the new file:一个简单的解决方法是让 unity为您自动生成 mainTemplate.gradle文件,然后将您的更改应用于新文件:

1) Copy the current contents of Assets/Plugins/Android/mainTemplate.gradle file. 1) 复制 Assets/Plugins/Android/mainTemplate.gradle 文件的当前内容。 (Or simply have source control to show you the diff) (或者只是让源代码控制向您展示差异)

2) Delete the Assets/Plugins/Android/mainTemplate.gradle file. 2) 删除 Assets/Plugins/Android/mainTemplate.gradle 文件。

3) In the Android Player Settings window -> Publishing Settings: Check the "Custom Gradle Template". 3) 在 Android 播放器设置窗口 -> 发布设置:勾选“自定义 Gradle 模板”。 That will generate a new mainTemplate.gradle file for you.这将为您生成一个新的 mainTemplate.gradle 文件。

4) Compare new file with the old one - and apply changes you need to the new file. 4)将新文件与旧文件进行比较 - 并将您需要的更改应用于新文件。

It would be great if you please share the build.gradle that's failing to build.如果您能分享构建失败的 build.gradle,那就太好了。

However, just going by the error you received, could you please apply thew plugin "java-library" if not applied already?但是,根据您收到的错误,如果尚未应用,您能否应用插件“java-library”?

Please apply the plugin for "allprojects" if it's a multi-module gradle project.如果它是一个多模块 gradle 项目,请为“allprojects”应用插件。 Otherwise, it needs to be added for the root project.否则,需要为根项目添加它。

apply plugin: 'java-library'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM