Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android studio 3.1: build:gradle:3.1.0 - Absolute path are not supported when setting an output file name

When I use Android Studio 3.0 and I use the next version of Android Gradle Plugin in project/build.gradle:

classpath 'com.android.tools.build:gradle:3.0.1'

And it's work fine. After I update to Android Studio 3.1 , as result I update Android Gradle Plugin :

classpath 'com.android.tools.build:gradle:3.1.0'

And now I get error in my app/build.gradle:

def releaseFileName = "${rootProject.name}_${defaultConfig.versionName}.apk"
outputFileName = new File(rootProject.projectDir.absolutePath + "/release", releaseFileName.toLowerCase())

Error:

Absolute path are not supported when setting an output file name

I need to put output apk (app-release.apk) in specific path in project. In folder MyProject/release/app-relese.apk. How I can do this?

like image 304
Alexei Avatar asked Mar 28 '18 08:03

Alexei


People also ask

How do I change the gradle path in Android Studio?

To change its path go to this path File > Settings... > Build, Execution, Deployment > Gradle In the Global Gradle settings Change Service directory path to what you want.

How do I fix gradle issues?

For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.

Where is build gradle File in Android Studio?

The top-level build.gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.


2 Answers

Just in case this helps, this error means that now it's not allowed to have absolute paths on anything related to the apk's file name. I can attach you my BEFORE and AFTER to achieve what I needed (to have the APK in the project/app/build/ folder:

BEFORE gradle 3.1.0

applicationVariants.all { variant ->
    variant.outputs.all { output ->
        outputFileName = new File(
                output.outputFile.parent,
                output.outputFile.name)
    }
}

IN or AFTER gradle 3.1.0

applicationVariants.all { variant ->
    variant.outputs.all { output ->
        outputFileName = new File(
                "./../../../../../build/",
                output.outputFile.name)
    }
}
like image 103
José Luis Ametller Avatar answered Sep 27 '22 21:09

José Luis Ametller


I think using "./../../../" is bad solution... I use common gradle script for several projects and I want to make code to be independency from depth of output dir.

After some researching I found this solution for gradle plugin 3.1.2:

applicationVariants.all { variant ->
    variant.outputs.all { output ->
        def relativeRootDir = output.packageApplication.outputDirectory.toPath()
                 .relativize(rootDir.toPath()).toFile()
        output.outputFileName = new File( "$relativeRootDir/release", newOutputName)
    }
}
like image 26
user3155340 Avatar answered Sep 27 '22 23:09

user3155340