![](/img/trans.png)
[英]How to override gradle.properties of a Cordova project from a plugin?
[英]How to prevent gradle.properties from being overwritten in Cordova Android?
在 Cordova (11.0.0) 项目中,在为 Android ("cordova-android": "^10.1.2")
平台构建时,我从 gradle(7.4.2) 收到此错误: Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module
。
根据这个答案和这个答案,它与 Java 18 相关,可以通过向 gradle.properties 添加一些属性来解决这个问题。
需要编辑的文件为platforms/android/gradle.properties
, 建议使用before_build
hook脚本修改该文件。
我已经这样做并确认我的脚本正确复制了我的 gradle.properties 版本。 然而,随后有一些东西用文件的默认版本覆盖了它。
如何防止我的文件版本被默认版本覆盖?
要修复 jvmargs,需要修改:node_modules\cordova-android\lib\config\GradlePropertiesParser.js :
_configureProperties (properties) {
// Iterate though the properties and set only if missing.
Object.keys(properties).forEach(key => {
const value = this.gradleFile.get(key);
if (!value) {
// Handles the case of adding missing defaults or new properties that are missing.
events.emit('verbose', `[Gradle Properties] Appending configuration item: ${key}=${properties[key]}`);
this.gradleFile.set(key, properties[key]);
} else if (value !== properties[key]) {
if (this._defaults[key] && this._defaults[key] !== properties[key]) {
let shouldEmit = true;
if (key === 'org.gradle.jvmargs') {
shouldEmit = this._isJVMMemoryLessThanRecommended(properties[key], this._defaults[key]);
}
if (shouldEmit) {
// Since the value does not match default, we will notify the discrepancy with Cordova's recommended value.
events.emit('info', `[Gradle Properties] Detected Gradle property "${key}" with the value of "${properties[key]}", Cordova's recommended value is "${this._defaults[key]}"`);
}
} else {
// When the current value exists but does not match the new value or does matches the default key value, the new value it set.
events.emit('verbose', `[Gradle Properties] Updating Gradle property "${key}" with the value of "${properties[key]}"`);
}
// We will set the new value in either case.
this.gradleFile.set(key, properties[key]);
}
});
//add this line here (Ben) :
this.gradleFile.set('org.gradle.jvmargs', this.gradleFile.get('org.gradle.jvmargs') + " --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.