27

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.

Don't upgrade to Android Studio 3

Bill
  • 545
  • 2
  • 5
  • 16
  • Android Gradle plugin 3 has some regressions so I suggest to use Android Studio 3 but do not upgrade Gradle plugin in your Cordova project. – Greg Dan Nov 03 '17 at 10:51
  • I had already updated everything. I learned my lesson. go check all the sources before updating things. – Bill Nov 03 '17 at 20:03

9 Answers9

109

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
Manmohan Pal
  • 1,577
  • 1
  • 12
  • 13
18

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);
andymoyle
  • 438
  • 4
  • 13
  • 1
    This is the winning solution for me that allows continual builds without having the build.gradle file getting overwritten – Peter P. Dec 05 '18 at 01:00
  • This is exactly what i needed too, due to GradleBuilder.js overwriting the changes mentioned in other answers – Gvstrmrgh Sep 02 '22 at 15:30
11

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
}
Gholamali Irani
  • 4,391
  • 6
  • 28
  • 59
Damir Varevac
  • 341
  • 2
  • 10
10

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
David
  • 7,387
  • 3
  • 22
  • 39
4

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
}
Pang
  • 9,564
  • 146
  • 81
  • 122
2

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)

coladict
  • 4,799
  • 1
  • 16
  • 27
  • 1
    What I don't quite get is why this isn't fixed in cordova-android itself? Surely other people are having this issue? – eAi May 03 '18 at 13:17
2

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!

Nisarg
  • 1,631
  • 6
  • 19
  • 31
0

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.

0

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
}
metamagikum
  • 1,307
  • 15
  • 19