You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级SDK至API Level33时遇module java.base权限错误求助

Android SDK升级到API 33时的processReleaseMainManifest错误解决

错误详情

升级SDK从API Level 30到33后,执行构建任务时出现以下错误:

Task :app:processReleaseMainManifest FAILED
Execution failed for task ':app:processReleaseMainManifest'.
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 @719420ff

项目build.gradle配置

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.8, 0.99.99]'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 33
    defaultConfig {
        applicationId "com.paulodybala.wallpaper"
        android {
            defaultConfig {
                manifestPlaceholders = [
                        onesignal_app_id: '25b96428-90da-48c1-abc4-4ded6d74bf70',
                        // Project number pulled from dashboard, local value is ignored.
                        onesignal_google_project_number: 'REMOTE'
                ]
            }
        }
        minSdkVersion 21
        targetSdkVersion 33
        versionCode 3
        versionName "1.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
//    implementation 'com.google.android.gms:play-services-ads:17.1.1'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
    implementation 'com.daimajia.numberprogressbar:library:1.4@aar'
    implementation 'com.turki-alkhateeb:materialcolorpicker:1.0.7'
    //ImageView
    implementation 'com.github.safetysystemtechnology:progress-image-view-android:v1.0'
    //optionMenu
    implementation 'io.github.yavski:fab-speed-dial:1.0.6'
    //ButterKinfie
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
    //Circular Rounded Image View
    implementation 'com.jackandphantom.android:circularimageview:1.2.0'
    //PaperDB
    implementation 'io.paperdb:paperdb:2.6'
    //RxDownloader
    implementation 'com.github.esafirm:RxDownloader:1.0.1'
    // Permissions
    implementation 'com.nabinbhandari.android:permissions:3.8'
    // Glide
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    //ImageShare
    implementation 'com.github.Omega-R.OmegaIntentBuilder:core:1.1.6'
    // For extras
    implementation 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.1.6'
    annotationProcessor 'com.github.Omega-R.OmegaIntentBuilder:processor:1.1.6'
    //MultiDux
    implementation 'androidx.multidex:multidex:2.0.0'
//    implementation 'com.android.support:multidex:1.0.3'

    //LotieView
    implementation 'com.airbnb.android:lottie:3.0.7'
    //DialogBox
    implementation 'com.github.TutorialsAndroid:KAlertDialog:v7.0.19'

    //facebook Audience Network
    implementation 'androidx.annotation:annotation:1.0.0'
    implementation 'com.facebook.android:audience-network-sdk:6.1.0'

    //onesignal
    implementation 'com.onesignal:OneSignal:[3.15.0, 3.99.99]'
//    implementation "androidx.core:core-ktx:1.6.0"
}

解决步骤

1. 修复build.gradle中的配置错误

当前配置里defaultConfig嵌套了多余的android -> defaultConfig层级,会导致Manifest处理逻辑异常,直接移除嵌套,将manifestPlaceholders移到外层defaultConfig下:

android {
    compileSdkVersion 33
    defaultConfig {
        applicationId "com.paulodybala.wallpaper"
        // 直接在这里配置manifestPlaceholders
        manifestPlaceholders = [
                onesignal_app_id: '25b96428-90da-48c1-abc4-4ded6d74bf70',
                onesignal_google_project_number: 'REMOTE'
        ]
        minSdkVersion 21
        targetSdkVersion 33
        versionCode 3
        versionName "1.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        multiDexEnabled true
    }
    // ... 其他配置
}

2. 升级Gradle与Android Gradle插件(AGP)

API 33需要AGP 7.0+及对应Gradle版本支持:

  • 修改根目录gradle/wrapper/gradle-wrapper.properties中的Gradle版本:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
    
  • 在根build.gradle的buildscript中添加/升级AGP和OneSignal插件:
    buildscript {
        repositories {
            maven { url 'https://plugins.gradle.org/m2/'}
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.4.2'
            classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.14.0'
        }
    }
    

3. 添加JVM参数解决反射权限问题

如果暂时无法升级依赖,可在项目根目录的gradle.properties中添加以下参数,允许反射访问java.io模块:

org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED

4. 升级老旧依赖版本

项目中大量依赖版本过旧(如appcompat 1.0.0、Glide 4.9.0),这些版本可能不兼容API 33,建议升级到最新稳定版,示例:

  • androidx.appcompat:appcompat:1.6.1
  • com.google.android.material:material:1.9.0
  • com.bumptech.glide:glide:4.15.1
  • com.airbnb.android:lottie:6.1.0

内容的提问来源于stack exchange,提问作者Muhammad Muzammil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 15:54:57