Here's my Ionic Info
cli packages: (/Users/billb/dev/customer-mkt-app/node_modules)
@ionic/cli-utils : 1.15.2
ionic (Ionic CLI) : 3.15.2
global packages:
cordova (Cordova CLI) : 7.0.1
local packages:
@ionic/app-scripts : 3.0.1
Cordova Platforms : android 6.2.3 ios 4.4.0
Ionic Framework : ionic-angular 3.3.0
System:
Android SDK Tools : 26.1.1
ios-deploy : 1.9.2
Node : v6.11.5
npm : 3.10.10
OS : macOS Sierra
Xcode : Xcode 9.0.1 Build version 9A1004
Environment Variables:
ANDROID_HOME : /Users/billb/Library/Android/sdk
Misc:
backend : pro
I can successfully build the app. When I try to open it in Android Studio, I get a handful of errors, mostly around a gradle sync failure. Here's the 5 errors in the Messages console.
Unable to resolve dependency for ':@debug/compileClasspath': Could not resolve project :CordovaLib. Could not resolve project :CordovaLib.
Required by: project :
Project : declares a dependency from configuration 'debugCompile' to configuration 'debug' which is not declared in the descriptor for project >:CordovaLib.
Unable to resolve dependency for ':@debugAndroidTest/compileClasspath': Could not resolve project :CordovaLib. Could not resolve project :CordovaLib.
Required by: project :
Project : declares a dependency from configuration 'debugCompile' to configuration 'debug' which is not declared in the descriptor for project >:CordovaLib.
Unable to resolve dependency for ':@debugUnitTest/compileClasspath': Could not resolve project :CordovaLib. Could not resolve project :CordovaLib.
Required by: project :
Project : declares a dependency from configuration 'debugCompile' to configuration 'debug' which is not declared in the descriptor for project > :CordovaLib.
Unable to resolve dependency for ':@release/compileClasspath': Could not resolve project :CordovaLib.
Could not resolve project :CordovaLib. Required by: project :
Project : declares a dependency from configuration 'releaseCompile' to configuration 'release' which is not declared in the descriptor for project :CordovaLib.
Unable to resolve dependency for ':@releaseUnitTest/compileClasspath': Could not resolve project :CordovaLib.
Could not resolve project :CordovaLib. Required by: project :
Project : declares a dependency from configuration 'releaseCompile' to configuration 'release' which is not declared in the descriptor for project :CordovaLib.
I really don't know what this means and Google hasn't turned up anything of any real help. What do I need to do here?
Note: discovered this after posting this. Relaying it here in case it will help someone else.
I commented the lines below in the build.gradle file:
//debugCompile project(path: 'CordovaLib', configuration: 'debug')
//releaseCompile project(path: 'CordovaLib', configuration: 'release')
and added:
compile project(':CordovaLib')
This worked for me.
If you are using Cordova build.gradle is automatically generated and when you next build the project the change in accepted answer above get overwritten back to the old that doesn't work.
So edit platforms/android/cordova/lib/builder/GradleBuiler.js Comment out lines 136-139 and add the next line
/*depsList += ' debugCompile(project(path: "' + libName + '", configuration: "debug"))';
insertExclude(p);
depsList += ' releaseCompile(project(path: "' + libName + '", configuration: "release"))';
insertExclude(p);
*/
depsList += " compile project(':CordovaLib')";
insertExclude(p);
If you get this kind of error in Android Studio 3.0.1:
Unable to resolve dependency for :@debug/compileClasspath’: Could not resolve project :CordovaLib.
Go to build.gradle file -> find dependencies and change it like this
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
//debugCompile(project(path: "CordovaLib", configuration: "debug"))
//releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile project(':CordovaLib')
// SUB-PROJECT DEPENDENCIES END
}
This is a known problem you can find the related jira issue here and the underlying problem is this one and both are "in progress". And there is already a pull request on github which you can try out but I can't promise you that it is already a working version. You can install it like this if you would like to try that:
cordova platform add https://github.com/infil00p/cordova-android.git#StudioThreeFix
Add this in Android build .gradle dependencies. That's all.
compile project(':CordovaLib')
For example:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
//debugCompile(project(path: "CordovaLib", configuration: "debug"))
//releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile project(':CordovaLib')
compile "com.android.support:support-v4:24.1.1+"
compile "com.google.android.gms:play-services-analytics:+"
// SUB-PROJECT DEPENDENCIES END
}
So, I just spent two days battling this and came-up with a semi-manual solution.
Because Gradle decided to uproot it's dependency format without any grace period for migration, we're forced to do things like this.
(Instructions under Linux. For Windows you'd need some 7zip or something similar for the last step)
From your user home directory go to .cordova/lib/npm_cache/cordova-android.
In there, there should be one or more folders with version numbers.
Usually only the latest version is run.
Open it.
Delete the package directory, but not the package.tgz file.
Unpack the package.tgz file, then delete it, or move it to a backup location. (there are some extra files generated that we don't want to re-package later)
Edit the file package/bin/templates/cordova/lib/plugin-build.gradle and inside dependencies remove these lines
debugCompile project(path: ":CordovaLib", configuration: "debug")
releaseCompile project(path: ":CordovaLib", configuration: "release")
Replace them with
implementation project(path: ":CordovaLib")
Archive the package directory. In Linux the short command is tar czf package.tgz package. On Windows, you'd have to create a .tar.gz archive with 7zip and rename it to .tgz.
After that, in running a cordova prepare in a clean repository that worked with the old versions will work again, unless some of the plugins explicitly use the old declaration format and need to be updated (example)
Ok, i found a solution.
I was using cordova-android: 6.3.0. I updated the version to 7.1.0 and then changed this line in the config.xml
before was:
<preference name="android-minSdkVersion" value="16" />
Now i'm using:
<preference name="android-minSdkVersion" value="19" />
This way, ionic cordova run android is working again without having to change those lines in build.gradle!
When you are facing this type of problem, you just de-grade the gradle version to 2.2.3 and re-sync the project it will work.
Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be removed at the end of 2018.
Simply replace 'compile' with 'implementation'
dependencies {
// SUB-PROJECT DEPENDENCIES START
//debugCompile(project(path: "CordovaLib", configuration: "debug"))
//releaseCompile(project(path: "CordovaLib", configuration: "release"))
implementation project(':CordovaLib')
// SUB-PROJECT DEPENDENCIES END
}
来源:https://stackoverflow.com/questions/47023068/unable-to-run-ionic-app-after-update-to-android-studio-3-0