Can't add module dependency to CordovaLib for Cordova project using Android Studio

冷暖自知 提交于 2019-12-10 14:32:54

问题


I can't workout how to add the CordovaLib directory as a module dependency in Android Studio.

(NOTE: this is the first time I've ever used Android Studio, so possibly I just don't know what I'm doing)

I'm using:

  • OSX Yosemite
  • Android Studio 1.1.0
  • Cordova 4.3

Here are the steps I have taken:

  1. Create new cordova project
  2. Add android platform and some cordova plugins
  3. Import the generated project into Android Studio (NOTE: when it asks about the gradle wrapper, I say no and just point it to where I have gradle installed - /usr/local/Cellar/gradle/2.2.1/libexec)
  4. Try to build - at this point it will complain for several of the Cordova plugins that cannot find symbol class CordovaPlugin

Obviously it doesn't know about the CordovaLib subproject. This is what I'm trying to fix.

I can't work out how to tell the Android Studio that CordovaLib is a module dependency.

I've gone to the Project Structure window, but can't see any way to link to CordovaLib.

Clicking the "+" buttons does not do anything. I can't work out if I'm doing something wrong, or there are bugs in Android Studio when importing the project...

Can someone please confirm if I'm doing something wrong?

Or please confirm if they are able to import Cordova generated projects into Android Studio, using Cordova 4.3 and Android Studio 1.1.0.

Thanks!


回答1:


First, thanks to @jcesarmobile for putting me on the right track.

Here is how to use the latest cordova-android directly (4.0.0-dev) from Github with Android Studio:

  1. Clone the cordova-android repo:

    git clone git@github.com:apache/cordova-android.git
    
  2. Add the platform to your cordova project

    cordova platform add /path/to/cloned/repo/cordova-android
    
  3. Build the project

    cordova build android
    
  4. Import into Android Studio as a non-android-studio project




回答2:


I had the same problem, is because there are error to load the module CordovaLib. You have to make this two steps:

1.- In root file (Android) add a file named "settings.gradle" with the content:

include ':CordovaLib'
project(':CordovaLib').projectDir = new File('CordovaLib')

2.- Go to file "build.gradle" and find this part:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    // SUB-PROJECT DEPENDENCIES END
}

and change it to:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':CordovaLib')
    // SUB-PROJECT DEPENDENCIES START
    // SUB-PROJECT DEPENDENCIES END
}

Now you just have to Run the project.



来源:https://stackoverflow.com/questions/29048639/cant-add-module-dependency-to-cordovalib-for-cordova-project-using-android-stud

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