簡體   English   中英

如何防止gradle.properties在Cordova Android中被覆蓋?

[英]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");
}

Cordova 編譯問題 gradle 版本 7.5.1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM