如何在Gradle 6.5.1中获取项目的相对路径apk。

huangapple go评论102阅读模式
英文:

How to get relative path apk of my project in gradle 6.5.1

问题

我将gradle版本从5.6.1更改为6.5.1,并将'com.android.tools.build:gradle:3.5.0'更改为'com.android.tools.build:gradle:4.0.1'。
之后,我遇到了构建失败的错误。

  • 出现了什么问题:
    配置项目':app'时出现问题。

groovy.lang.MissingMethodException:org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar.toPath()方法没有签名,适用于参数类型:()值:[]
可能的解决方案:with(groovy.lang.Closure),each(groovy.lang.Closure),tap(groovy.lang.Closure),with(boolean,groovy.lang.Closure),getAt(java.lang.String),putAt(java.lang.String,java.lang.Object)

我理解在新的gradle中不存在.toPath()方法,但是是否添加了其他替代方法到新的gradle中呢?或者是否存在另一种方法来获取项目的相对路径?

以下是代码示例:

buildTypes {
    release {
        applicationVariants.all { variant ->
            variant.outputs.all { output ->
                def relative_apk_folder = output.packageApplication.outputDirectory.toPath().relativize(project.rootDir.toPath()).toString() + "/bin/";
                outputFileName = new File("$relative_apk_folder" + "MyAPK.apk")
            }
        }
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.sign_app
    }
    debug {
    }
}
英文:

I changed gradle version 5.6.1 to 6.5.1 and also 'com.android.tools.build:gradle:3.5.0' to 'com.android.tools.build:gradle:4.0.1'.
After that I got FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> groovy.lang.MissingMethodException: No signature of method: org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar.toPath() is applicable for argument types: () values: []
  Possible solutions: with(groovy.lang.Closure), each(groovy.lang.Closure), tap(groovy.lang.Closure), with(boolean, groovy.lang.Closure), getAt(java.lang.String), putAt(java.lang.String, java.lang.Object)

I understand that in new gradle does not exist method .toPath(), but what alternative was added to new gradle? Or is it exist another way to get relative path of my project?

here is code example:

buildTypes {
        release {
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    def relative_apk_folder = output.packageApplication.outputDirectory.toPath().relativize(project.rootDir.toPath()).toString() + "/bin/"
                    outputFileName = new File("$relative_apk_folder" + "MyAPK.apk")
                }
            }
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.sign_app
        }
        debug {
        }
    }

答案1

得分: 0

试试这个

def relative_apk_folder = "../../../../../bin/"
outputFileName = new File(relative_apk_folder + "MyAPK.apk")

在我的项目中有帮助
英文:

Try this one:

def relative_apk_folder = "../../../../../bin/" outputFileName = new File(relative_apk_folder + "MyAPK.apk")

It helped in my project.

huangapple
  • 本文由 发表于 2020年7月24日 20:51:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63073946.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定