Unable to run Ionic app after update to Android Studio 3.0

。_饼干妹妹 提交于 2019-11-28 17:15:41
Manmohan Pal

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);
Damir Varevac

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
user9025015

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)

Joao Victor Cachola

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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!