android 使用Cordova构建移动的应用程序时,任务“:app:compileDebugJavaWithJavac”执行失败

jvlzgdj9  于 2023-01-07  发布在  Android
关注(0)|答案(1)|浏览(165)

我尝试使用Cordova构建一个应用程序(使用 * cordova build android *),不幸的是,我遇到了这个错误"执行任务失败:app:compiledebugJavaWithJavac'"。我提供了我能想到的所有必要信息。

  • cordova 版本:* * 11.0.0版本**
  • Cordova安装的平台:安卓系统9.1.0,操作系统5.1.1
  • Java版本:* * 1.8.0第341条**
  • NPM版本:* * 15年14月6日**
  • 节点版本:* * 2001年18月14日**
  • JAVA主目录路径:第一个月
  • Android SDK平台:* * 从API级别29到32**
  • Android SDK工具:* * 从API级别29到32**

工作机器:配备M1 CPU的MacBook Pro,macOS:文图拉13.1
我的config.xml文件:

<?xml version='1.0' encoding='utf-8'?>
<widget
        android-packageName="com.test.testapp"
        ios-CFBundleIdentifier="com.test.testapp"
        version="1.0.0"
        xmlns="http://www.w3.org/ns/widgets"
        xmlns:cdv="http://cordova.apache.org/ns/1.0"
        xmlns:android="http://schemas.android.com/apk/res/android">
    <name>Test App</name>
    <description>
        Just a Test App.
    </description>
    <author email="test@test.com" href="http://test.com">
        Test Team
    </author>
    <content src="sourcePath"/>
    <plugin name="cordova-plugin-whitelist" spec="1"/>
    <access origin="*"/>
    <allow-intent href="http://*/*"/>
    <allow-intent href="https://*/*"/>
    <allow-intent href="tel:*"/>
    <allow-intent href="sms:*"/>
    <allow-intent href="mailto:*"/>
    <allow-intent href="geo:*"/>
    <allow-navigation href="https://*/*" />
    <preference name="Orientation" value="portrait"/>
    <platform name="android">
        <icon src="../assets/android/icon.png"/>
        <allow-intent href="market:*"/>
        <preference name="android-targetSdkVersion" value="31"/>
        <preference name="AndroidXEnabled" value="true" />
        <config-file parent="/manifest/application" target="AndroidManifest.xml">
            <meta-data
                android:name="com.google.android.gms.wallet.api.enabled"
                android:value="true" />
        </config-file>
        <edit-config file="AndroidManifest.xml" target="/manifest/application/activity" mode="merge">
            <activity android:exported="true"/>
        </edit-config>
    </platform>
    <platform name="ios">
        <feature name="CDVWKWebViewEngine">
            <param name="ios-package" value="CDVWKWebViewEngine"/>
        </feature>
        <allow-navigation href="*://js.stripe.com/*"/>
        <allow-navigation href="*://stripe.com/*"/>
        <allow-intent href="itms:*"/>
        <allow-intent href="itms-apps:*"/>
        <edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
            <string>Needs for locating user's order delivery address</string>
        </edit-config>
        <edit-config target="NSLocationAlwaysUsageDescription" file="*-Info.plist" mode="merge">
            <string>Needs for locating user's order delivery address</string>
        </edit-config>
        <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine"/>
        <preference name="StatusBarOverlaysWebView" value="false"/>
        <preference name="StatusBarBackgroundColor" value="000000"/>
        <preference name="WKWebViewOnly" value="true"/>
    </platform>
    <preference name="SplashScreenDelay" value="0"/>
    <engine name="android" spec="<9.0.0"/>
    <engine name="ios" spec="~5.1.1"/>
</widget>

我的package.json文件:

{
  "name": "helloworld",
  "displayName": "HelloCordova",
  "version": "1.0.0",
  "description": "A sample Apache Cordova application that responds to the deviceready event.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "ecosystem:cordova"
  ],
  "author": "Apache Cordova Team",
  "license": "Apache-2.0",
  "dependencies": {
    "cordova-android": "^9.0.0",
    "cordova-ios": "^5.1.1",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-geolocation": "^4.0.1",
    "cordova-plugin-inappbrowser": "^3.2.0",
    "cordova-plugin-network-information": "^2.0.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "1.3.4",
    "cordova-plugin-wkwebview-engine": "^1.2.1",
    "cordova-plugin-x-toast": "^2.7.3",
    "es6-promise-plugin": "^4.2.2",
    "xml-js": "^1.6.11"
  },
  "devDependencies": {},
  "cordova": {
    "plugins": {
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-wkwebview-engine": {},
      "cordova-plugin-x-toast": {},
      "cordova-plugin-geolocation": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {}
    },
    "platforms": [
      "android",
      "ios"
    ]
  }
}

我的generate_builds. sh文件:

### Constants

# Must be equal to <widget> -> <name> in app/config.xml file
APP_NAME="Test App"

### Operations

# navigate to app/ directory
cd app/

# delete all generated folders
rm -rf platforms/ node_modules/

# run npm install to make sure that new libraries are installed
npm install

# this command will add all plugins listend in package.json file in /plugins folder and also generate ios and android platforms
cordova prepare

# Add Plugman plugins - we use Plugman to install some plugins only for android platform and some only for iOS platform. In this way we avoid plugin conflicts.
# IMPORTANT: Plugins installed with Plugman are not listed in the package.json neither in config.xml files

# for ios platform
plugman install --platform ios --project ./platforms/ios/ --plugin cordova-plugin-firebasex --plugins_dir ./plugins/
plugman install --platform ios --project ./platforms/ios/ --plugin cordova-plugin-stripe --plugins_dir ./plugins/
plugman install --platform ios --project ./platforms/ios/ --plugin cordova-plugin-dynamic-applepay-stripe --plugins_dir ./plugins/

# for android platform
plugman install --platform android --project ./platforms/android/ --plugin cordova-plugin-firebasex --plugins_dir ./plugins/
plugman install --platform android --project ./platforms/android/ --cordova-plugin-androidx --plugins_dir ./plugins/
plugman install --platform android --project ./platforms/android/ --cordova-android-play-services-gradle-release --plugins_dir ./plugins/
plugman install --platform android --project ./platforms/android/ --plugin cordova-plugin-apple-pay-google-pay --plugins_dir ./plugins/
# Replace all iOS image folder with the one from /app/assets/ios/Images.xcassets

# delete generated folders
rm -rf platforms/ios/"$APP_NAME"/Images.xcassets/
cp -r ../assets/ios/Images.xcassets/ platforms/ios/"$APP_NAME"/Images.xcassets/

# Add firebase push notification files in ios and android platforms

# ios

rm -f platforms/ios/"$APP_NAME"/Resources/GoogleService-Info.plist
cp  ../assets/ios/firebase/GoogleService-Info.plist platforms/ios/"$APP_NAME"/Resources/GoogleService-Info.plist

# android

rm -f platforms/android/app/google-services.json
cp  ../assets/android/firebase/google-services.json platforms/android/app/google-services.json

# Replace Google Pay plugin files in android platform.

rm -f platforms/android/app/src/main/java/com/plugin/googlepay/ApplePayGooglePay.java
cp  ../assets/android/gpay/ApplePayGooglePay.java platforms/android/app/src/main/java/com/plugin/googlepay/ApplePayGooglePay.java

有关错误的详细信息:

> Task :app:compileDebugJavaWithJavac
/Users/userName/Documents/Projects/TestApp/app/platforms/android/app/src/main/java/org/apache/cordova/firebase/FirebasePluginMessagingService.java:261: error: cannot find symbol
            if(getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
                                                                           ^
  symbol:   variable S
  location: class VERSION_CODES
/Users/userName/Documents/Projects/TestApp/app/platforms/android/app/src/main/java/org/apache/cordova/firebase/FirebasePluginMessagingService.java:261: error: cannot find symbol
            if(getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
                                                                                                                             ^
  symbol:   variable S
  location: class VERSION_CODES
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/userName/Documents/Projects/TestApp/app/platforms/android/app/src/main/java/org/apache/cordova/firebase/FirebasePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

> Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

我已经尝试了许多可能的解决方案,发现这里在StackOverflow,到目前为止没有帮助我的问题。任何建议都是非常欢迎和高度赞赏!

brccelvz

brccelvz1#

这个错误显然来自FirebasePluginMessagingService。但是我没有看到它是在哪里添加的。所以我猜它是由plugman添加的,因为你记录了Plugins installed with Plugman are not listed in the package.json neither in config.xml files。你能试着删除那个插件,看看你的项目是否能构建吗?这个错误出现了,因为S不存在于你旧的targetSDK中(我相信S是31)source:Build failed error: cannot find symbol if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)。所以看看你是否可以使用旧版本的插件或更高版本的targetSDK。为此,你可能还需要增加cordova-android。
我认为重要的是要有一个工作的项目作为起点,这就是为什么我会删除插件第一。然后升级所需的版本,然后才添加回插件。我更新了 cordova Android从9到11在几个步骤,也从29到31 targetSDK在2个步骤。在每一个步骤中,至少有一件事打破了,所以试图同时做几件这样的事情几乎是不可能的。一些坏掉的事情是:

  • Jdk需要从8升级到至少11(我想这是targetSDK 30所要求的)
  • 白名单插件和它的每一个参考需要被删除(也在插件中,通过打补丁)(由cordova 10+要求)
  • 节点必须至少为14
  • <engine name="android" spec="<9.0.0"/>这个规格看起来和你使用的cordova-android版本有冲突。我不确定哪些更新需要什么。但是cordova更新文档应该告诉你,它们存在于每个版本中:https://cordova.apache.org/announcements/2021/07/20/cordova-android-10.0.0.html targetSDK版本本身也有一些要求,所以一定要检查这些要求。

相关问题