简体   繁体   中英

Cordova Project Error : spawn EACCES

Just 1 week back i was able to run same project on same Mac machine, but after upgrading my system android studio to 3.0 stable release , this Cordova project has stopped building both from console and through android studio.

Please check below is the console run command exception log

 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 Error log:

Could not find com.android.tools.build:gradle:2.3.3. Searched in the following locations: 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 Required by: project :CordovaLib Add Google Maven repository and sync project Open File

Found solution myself, copy/pasted the below given buildscript and dependencies into android studio Cordova library 'build.gradle' and also in project level 'build.gradle' :

buildscript {
    repositories {
        mavenCentral()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }

}

and now i am able to build the project again.

Update: turns out this is a known Cordova/Android Studio 3.0 issue here . Basically Android Studio 3 removed support for an old build-by-convention project directory structure that Cordova is using. So only older android gradle plugin and gradle version pairs work (as is indicated below) until Cordova fixes the issue.

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

Steps to fix issue:

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) changed the Cordova "myApp/platforms/android" project's Android gradle plugin and gradle version pair to a pair supported by Cordova gradle build configuration and Android Studio 3.0 IDE. Old values are commented-out below.

.../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) chmod execution bits on Cordova platforms "android" directory and all subdirectories:

cd to .../myApp/platforms
chmod -R 755 android

Not sure this was required, do #1 first and test.

3) I did the same for my Android sdk directory and all its subdirectories. Not sure this was required, do #1 first and test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM