gradle.properties
中定义了一个绝对路径到 keystore 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/