ionic cordova android 构建失败(命令失败,退出代码 1:gradle)

问题描述 投票:0回答:1

我正在尝试通过 ionic cordova 构建 android 14(api 级别 34)。这是离子信息的错误。我对此一无所知。

离子信息

Ionic:

   Ionic CLI                     : 7.2.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.803.29
   @angular-devkit/schematics    : 8.3.29
   @angular/cli                  : 8.3.29
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 13.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 17 other plugins)

Utility:

   cordova-res (update available: 0.15.4) : 0.15.3
   native-run (update available: 2.0.1)   : 1.4.0

System:

   Android SDK Tools : 26.1.1 (/home/user/Android/Sdk)
   NodeJS            : v16.20.2 (/usr/local/bin/node)
   npm               : 8.19.4
   OS                : Linux 5.15

构建失败错误

Date: 2024-12-19T12:00:44.992Z - Hash: 893516b2e63dea55a99d - Time: 14179ms
> cordova build android
The "<splash>" tags were detected and are no longer supported. Please migrate to the "preference" tag "AndroidWindowSplashScreenAnimatedIcon".
cordova-plugin-androidx-adapter: Processed 75 source files in 1067ms
Checking Java JDK and Android SDK versions
ANDROID_HOME=/home/user/Android/Sdk (recommended setting)
ANDROID_SDK_ROOT=/home/user/Android/Sdk (DEPRECATED)
Using Android SDK: /home/user/Android/Sdk
Starting a Gradle Daemon, 2 incompatible Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().

* 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

BUILD FAILED in 1s
Command failed with exit code 1: gradle -p /home/user/Documents/beauty_salon_app_0817/platforms/android/tools wrapper --gradle-version 8.7
[ERROR] An error occurred while running subprocess cordova.
        
        cordova build android exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.

我尝试从 api 级别 29 升级到 api 级别 34。

  1. 更改config.xml中的“android-targetSdkVersion”,值=“34”

  2. Android Studio:安装Android 14.0(“UpsideDownCake”),API级别34

  3. Android Studio:Android SDK 构建工具 34.0.0

  4. 更新 Node.js

    sudo n 16

  5. 更新 Ionic CLI

sudo npm install -g @ionic/cli
npm install
  1. 更新JAVA
sudo apt-get update
sudo apt-get upgrade
sudo add-apt-repository ppa:openjdk-r/ppa    
sudo apt install openjdk-22-jdk                   //java 22 match gradle 8.7.0
java -version                             //Check java version
sudo update-alternatives --config java        //Run this command to choose version
echo $JAVA_HOME                   //Check java home
export JAVA_HOME=/usr/lib/jvm/java-22-openjdk-amd64 //Setting JAVA_HOME 
  1. 更新cordova android
cordova platform rm android
cordova platform add [email protected]
  1. 构建
    ionic cordova build android -info
cordova ubuntu ionic-framework android-api-levels
1个回答
0
投票

我通过更新Ubuntu系统gradle版本解决了这个问题。删除旧版本 gradle 4.x.x 并安装 gradle 8.7。

打开Ubuntu终端

sudo apt remove gradle
wget https://services.gradle.org/distributions/gradle-8.7-bin.zip
unzip gradle-8.7-bin.zip
sudo mv gradle-8.7 /opt/gradle
nano ~/.bashrc

添加/编辑以下行:

export GRADLE_HOME=/opt/gradle/gradle-8.7
export PATH=$PATH:$GRADLE_HOME/bin

保存并退出(Ctrl + X,然后 Y,然后 Enter)。

source ~/.bashrc
gradle -v

但是,还有更多的失败,我还在努力解决。

> cordova build android
cordova-plugin-androidx-adapter: Processed 75 source files in 1115ms
Checking Java JDK and Android SDK versions
ANDROID_HOME=/home/user/Android/Sdk (recommended setting)
ANDROID_SDK_ROOT=/home/user/Android/Sdk (DEPRECATED)
Using Android SDK: /home/user/Android/Sdk

BUILD SUCCESSFUL in 508ms
1 actionable task: 1 up-to-date
Subproject Path: CordovaLib
Subproject Path: app

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Script '/home/user/Documents/beauty_salon_app_0817/platforms/android/card.io.cordova.mobilesdk/ESTEBELSpa-build.gradle' line: 6

* What went wrong:
A problem occurred evaluating script.
> Could not find method compile() for arguments [io.card:android-sdk:5.4.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* 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.
==============================================================================

BUILD FAILED in 624ms
Command failed with exit code 1: /home/user/Documents/beauty_salon_app_0817/platforms/android/tools/gradlew cdvBuildDebug
[ERROR] An error occurred while running subprocess cordova.
        
        cordova build android exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.
© www.soinside.com 2019 - 2024. All rights reserved.