简体   繁体   中英

Unity3D - failed Build Android AppBundle using Gradle

currently, my game builds successfully if build using Unity's Internal System. Now because I need AppBundle over APK I try to change build system to Gradle like below picture:

在此处输入图片说明

However, in Gradle it returns an error.

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.

Note: I'm using Unity v2017.4.30f1

Any Idea to Solve?

Thank You

Change your mainTemplate.gradle file to something like this:

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.

An easy fix would be to let unity autogenerate the mainTemplate.gradle file for you, and then applying your changes on the new file:

1) Copy the current contents of Assets/Plugins/Android/mainTemplate.gradle file. (Or simply have source control to show you the diff)

2) Delete the Assets/Plugins/Android/mainTemplate.gradle file.

3) In the Android Player Settings window -> Publishing Settings: Check the "Custom Gradle Template". That will generate a new mainTemplate.gradle file for you.

4) Compare new file with the old one - and apply changes you need to the new file.

It would be great if you please share the build.gradle that's failing to build.

However, just going by the error you received, could you please apply thew plugin "java-library" if not applied already?

Please apply the plugin for "allprojects" if it's a multi-module gradle project. Otherwise, it needs to be added for the root project.

apply plugin: 'java-library'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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