Gradle 3.0 BuildException cannot create directory

后端 未结 4 861
栀梦
栀梦 2020-12-30 13:01

I\'m on windows and updated to Android Studio (AS) 3.0 RC1. When I try to built our project with gradle via AS or terminal it stops, the Stacktrace is at the end. The weird

相关标签:
4条回答
  • 2020-12-30 13:36

    In your gradle file (module level), are you using applicationVariants to rename your apk or things like this ? I had to remove this part in my gradle file to solve this issue.

    0 讨论(0)
  • 2020-12-30 13:55

    I am building same app with Android Studio 3.0 on both Linux or Windows. After upgrading to Gradle 3.0.1, I had a similar issue on Windows, while it was working fine on Linux:

    Error:Execution failed for task ':smsreminder:packageDebug'. > Cannot create directory C:\Users\Florent\AndroidStudioProjects\MyApp\myapp\build\outputs\apk\debug\C:\Users\Florent\AndroidStudioProjects\MyApp\myapp\build\outputs\apk\debug

    And thanks to above answer from Leo, I made this more friendly apk name:

    outputFileName = "${variant.name}-${variant.versionName}.apk"
    => produces: debug-x.y.apk
    
    outputFileName = output.outputFile.name + ".${variant.versionName}.apk"
    => produces: MyAppName.x.y.apk
    

    Otherwise, I found this working too if one want to keep default :

    if (org.gradle.internal.os.OperatingSystem.current().windows)
                outputFileName = "${variant.name}-${variant.versionName}.apk"
            else
                outputFileName = new File(output.outputFile.parent, outputFileName.replace(output.outputFile.name, defaultConfig.applicationId + ".apk"))
    
    0 讨论(0)
  • 2020-12-30 14:01

    With the stable release of Android Studio 3.0 I digged a little deeper. Turns out our script for naming the APK didn't work, but was only breaking on Windows.

    Old Script:

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = outputFile.name.replace('.apk', "-${versionName}.apk")
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }
    

    Fixed Script:

    applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${variant.name}-${variant.versionName}.apk"
        }
    }
    
    0 讨论(0)
  • 2020-12-30 14:03
    android.applicationVariants.all { variant ->
      variant.outputs.all {
          outputFileName = "${variant.name}-${variant.versionName}.apk"
    

    This code will fix the issue.!! There is a minor change to the above answer in this script

    0 讨论(0)
提交回复
热议问题