仅仅一周后我就可以在同一台Mac机器上运行相同的项目, 但升级后我的系统android studio升级到3.0稳定 发布时,这个Cordova项目已停止从控制台构建 并通过android studio。
请在下面查看控制台运行命令例外日志
Last login: Mon Nov 6 11:47:13 on ttys000
XKL-0439:~ LuckyRana$ sudo cordova create ERL com.xchanging.erla ERL
Password:
Creating a new cordova project.
XKL-0439:~ LuckyRana$ cordova platform add android --save
Error: Current working directory is not a Cordova-based project.
XKL-0439:~ LuckyRana$ cd ERL
XKL-0439:ERL LuckyRana$ sudo cordova platform add android --save
Using cordova-fetch for cordova-android@~6.3.0
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.xchanging.erla
Name: ERL
Activity: MainActivity
Android target: android-26
Subproject Path: CordovaLib
Android project created with cordova-android@6.3.0
Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project
Installing "cordova-plugin-whitelist" for android
This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in.
Adding cordova-plugin-whitelist to package.json
Saved plugin info for "cordova-plugin-whitelist" to config.xml
--save flag or autosave detected
Saving android@~6.3.0 into config.xml file ...
XKL-0439:ERL LuckyRana$ cordova requirements android
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-27,android-26,android-25,android-24,Google Inc.:Google APIs:24,android-23,Google Inc.:Google APIs:23,android-22,Google Inc.:Google APIs:22,android-21,Google Inc.:Google APIs:21
Gradle: installed /Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle
XKL-0439:ERL LuckyRana$ 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.
Error: EACCES: permission denied, open '/Users/LuckyRana/ERL/package.json'
XKL-0439:ERL LuckyRana$ sudo cordova run android
ANDROID_HOME=/Users/LuckyRana/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
Error: spawn EACCES
XKL-0439:ERL LuckyRana$
Android Studio错误日志:
找不到com.android.tools.build:gradle:2.3.3。在以下位置进行了搜索:https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.jar要求:项目:CordovaLib添加Google Maven存储库和同步项目打开文件
答案 0 :(得分:0)
自己找到解决方案,将下面给出的buildscript和依赖项复制/粘贴到android studio Cordova库' build.gradle'而且在项目层面' build.gradle' :
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
现在我能够再次构建项目。
答案 1 :(得分:0)
更新:结果证明这是一个已知的Cordova / Android Studio 3.0问题here。基本上Android Studio 3删除了对Cordova正在使用的旧的按会议项目目录结构的支持。所以只有较旧的android gradle插件和gradle版本对才能工作(如下所示),直到Cordova解决了这个问题。
MacOS X version -> 10.12.6
node --version -> 8.0.0
npm --version -> 5.5.1
cordova --version -> 7.1.0
Android Studio IDE -> 3.0
解决问题的步骤:
myApp > cordova run android
ANDROID_HOME=/Users/Luckyjohn/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home
Subproject Path: CordovaLib
Error: spawn EACCES
1)将Cordova“myApp / platforms / android”项目的Android gradle插件和gradle版本对更改为Cordova gradle构建配置和Android Studio 3.0 IDE支持的一对。旧值在下面注释掉了。
.../android build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
//classpath 'com.android.tools.build:gradle:2.2.3'
}
.../android/CordovaLib build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
//classpath 'com.android.tools.build:gradle:2.2.3'
.../gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
2)Cordova平台上的chmod执行位“android”目录和所有子目录:
cd to .../myApp/platforms
chmod -R 755 android
不确定这是必需的,先做#1然后测试。
3)我为我的Android sdk目录及其所有子目录做了同样的事情。不确定这是必需的,先做#1并测试。