cordova build a-6ren">
gpt4 book ai didi

android - Cordova Android 构建错误 "Cannot read property ' 未定义长度'

转载 作者:太空狗 更新时间:2023-10-29 13:52:16 25 4
gpt4 key购买 nike

我正在更新一个较旧的 cordova 项目。作为这个过程的一部分,我删除了 android 平台并重新添加了它。

现在,当我尝试构建项目时,出现以下错误:

C:\App>cordova build android --verbose
No scripts found for hook "before_build".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at C:\App\platforms\android\res\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Found "merges/android" folder. Copying its contents into the android project.
Merging and updating files from [www, platforms\android\platform_www, merges\android] to platforms\android\assets\www
Wrote out android application name "App" to C:\App\platforms\android\res\values\strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (1.0.20): 10020
Wrote out Android package name "com.nge.app" to C:\App\platforms\android\src\com\nge\bca\MainActivity.java
Updating icons at platforms\android\res
Updating splash screens at platforms\android\res
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
ANDROID_HOME=C:\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
Error: Cannot read property 'length' of undefined

这在我删除平台之前确实有效,所以我猜这是一个错误或更改的配置文件。

这里有一个类似的问题:https://pt.stackoverflow.com/questions/219442/cordova-build-android-error-cannot-read-property-length-of-undefined

最佳答案

我通过将 Android 降级到版本 6.1.2 找到了另一个解决方案,因为此处的建议(以及各种论坛上的许多其他建议,如重新安装插件等)对我不起作用:

cordova platform update android@6.1.2 --save

如果这对第一手不起作用,请尝试以下操作:

  1. 首先移除android平台:

    cordova platform remove android
  2. 添加 Android 版本 6.1.2:

    cordova platform add android@6.1.2
  3. 构建 Android:

    cordova build android

以下是我在上面(在 Mac 上)之前采取的一些额外步骤,只是为了确保:

  1. 下载最新的 JDK 并安装。

  2. 以这种方式添加 JAVA_HOME:

    echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
  3. 重启 shell(CMD+Q 再次打开)

  4. 确保 echo $JAVA_HOME 等于 Android Studio -> 文件 -> 项目结构 -> JDK 位置

对我来说,这是以下路径和版本:

/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

  1. 更新 Android Studio 和所有 SDK 包

  2. 更新 npm

    npm update -g

注意:在 OS X 10.11 El Capitan 或更高版本上,运行:

sudo npm update -g --unsafe-perm=true
  1. 更新 Cordova

    npm update -g cordova

如果所有这些都不适合您并且您别无选择,我建议您尝试将 Cordova 降级到版本 6.4.0:

npm update -g cordova@6.4.0

关于android - Cordova Android 构建错误 "Cannot read property ' 未定义长度',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45025219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com