无法构建支持 Android 12 的 Ionic android apk
Posted
技术标签:
【中文标题】无法构建支持 Android 12 的 Ionic android apk【英文标题】:Unable to build Ionic android apk that supports Android 12 【发布时间】:2021-12-31 19:38:52 【问题描述】:我正在尝试构建我的 Ionic 应用程序以支持 android 12。它在 Android 11 之前运行良好,但不支持 Android 12。
这是我迄今为止尝试过的:
package.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"
在 ..\platforms\android\app\src\main\AndroidManifest.xml 中的 MainActivity
中添加了 android:exported=“true”
在运行此构建时,我收到以下错误:
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
…\platforms\android\app\src\main\AndroidManifest.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: …\platforms\android\gradlew cdvBuildDebug -b …\platforms\android\build.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.
我已经尝试了所有论坛和帖子,但似乎没有任何效果。有人知道如何进行这项工作吗?
【问题讨论】:
【参考方案1】:有一个issue
#222 和FCM Plugin 仍未解决,所以我建议您降级插件版本安装,直到它得到修复。
【讨论】:
以上是关于无法构建支持 Android 12 的 Ionic android apk的主要内容,如果未能解决你的问题,请参考以下文章
安装cordova插件后我无法在ionic中构建android apk