无法构建支持android 12的Ionic android apk



我正在尝试构建我的Ionic应用程序以支持Android 12。它适用于Android 11,但不支持Android 12。

这就是我迄今为止所尝试的:

软件包.json

“cordova-android”: “^9.1.0”

build.gradle文件:

defaultBuildToolsVersion=“29.0.2”
defaultMinSdkVersion=22
defaultTargetSdkVersion=30
defaultCompileSdkVersion=30

config.xml文件:

preference name="android-targetSdkVersion" value="30"

===尝试将sdk增加到31===

package.json文件:

“cordova-android”: “^10.0.0”

build.gradle文件:

defaultTargetSdkVersion=31
defaultCompileSdkVersion=31

config.xml文件:

preference name="android-targetSdkVersion" value="31"

在..中的MainActivity中添加了android:exported="true"。。\platforms\android\app\src\main\AndroidManifest.xml

在运行此构建时,我得到以下错误:

FCMPlugin: Support for Gradle v4 or lower is deprecated. Please upgrade to a newer version.WARNING:: Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’.
It will be removed in version 7.0 of the Android Gradle plugin.
For more information, see Add build dependencies  |  Android Developers.
WARNING:: Using flatDir should be avoided because it doesn’t support any meta-data formats.
Task :app:processDebugMainManifest FAILED
…platformsandroidappsrcmainAndroidManifest.xml Error:
Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See <activity>  |  Android Developers for details.
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ‘:app:processDebugMainManifest’.
Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See <activity>  |  Android Developers for details.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use ‘–warning-mode all’ to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See Command-Line Interface
BUILD FAILED in 3s
15 actionable tasks: 1 executed, 14 up-to-date
Command failed with exit code 1: …platformsandroidgradlew cdvBuildDebug -b …platformsandroidbuild.gradle
[ERROR] An error occurred while running subprocess cordova.
cordova.cmd build android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.

我试过所有的论坛和帖子,似乎都不起作用。有人知道怎么做吗?

有一个带有FCM插件的issue#222尚未解决,因此我可能建议您降低插件版本安装,直到修复为止。

最新更新