gradle - Windows 上 build.gradle 中的绝对路径

标签 gradle

  • 我在 gradle.properties 中定义了一个绝对路径到 keystore
  • 我正在使用 Windows
  • 我在路径中有一个空白空间

    RELEASE_STORE_FILE="D:\我的文件夹\Android\android.javakeystore.keystore.jks"

  • 我收到错误
    The filename, directory name, or volume label syntax is incorrect
        at java.io.WinNTFileSystem.canonicalize0(Native Method)
        at java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:428)
        at java.io.File.getCanonicalPath(File.java:618)
        at java.io.File.getCanonicalFile(File.java:643)
        at org.gradle.api.internal.file.FileNormaliser.normalise(FileNormaliser.java:54)
        ... 222 more
    

    如何在 Gradle 中正确定义 Windows 上的绝对路径?

    最佳答案

    问题来自 gradle.properties 文件中您的属性值中周围的 "字符。您应该在 gradle.properties 中配置您的属性,如下所示:

    RELEASE_STORE_FILE=D:\\My Folder\\Android\\android.javakeystore.keystore.jks
    

    或者
    RELEASE_STORE_FILE=D:/My Folder/Android/android.javakeystore.keystore.jks
    

    Gradle 会保留属性值中的 "字符,因此如果您尝试这样的操作:
    file(RELEASE_STORE_FILE).exits() // if RELEASE_STORE_FILE contains " char, it will fail
    

    其他例子来说明这一点:

    gradle.properties
    cert_path_1=c:/my certs/cert.txt
    cert_path_2="c:/my certs/cert.txt"
    cert_path_3="c:\\my certs\\cert.txt"
    cert_path_4=c:\\my certs\\cert.txt
    

    构建.gradle
    void testFile(String message, String fileToTest){
        println message
        println " -> does the file exist? : " + file(fileToTest).exists() + "\n"
    }
    
    testFile("Testing property 'cert_path_1'", ext.cert_path_1)
    testFile("Testing property 'cert_path_2'", ext.cert_path_2)
    testFile("Testing property 'cert_path_3'", ext.cert_path_3)
    testFile("Testing property 'cert_path_4'", ext.cert_path_4)
    

    结果:
    Testing property 'cert_path_1'
     -> does the file exist? : true
    
    Testing property 'cert_path_2'
     -> does the file exist? : false
    
    Testing property 'cert_path_3'
     -> does the file exist? : false
    
    Testing property 'cert_path_4'
     -> does the file exist? : true
    

    关于gradle - Windows 上 build.gradle 中的绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52015368/

    相关文章:

    android - 502 google.bintray.com 网关错误

    android - android/flutter 中的 settings_aar.gradle 有什么用?

    android - 404 找不到资源 lint-gradle-26.1.3.pom

    Gradle 复制文件并仅展开其中的一些文件和/或忽略其他文件中的美元符号

    android - 在 Android Studio 中找不到\gradle-wrapper.properties

    gradle - 从已编译的源集中过滤类文件以添加到 Gradle/Groovy 的 JAR 中

    java - 如何构建创建 .exe 而不是 .jar 的 msi 安装程序?

    macos - 在Macbook上运行Gradle

    android - 如何为 Android Studio 构建模板项目

    intellij-idea - IntelliJ IDEA中的Xtend无法在src-gen中生成文件