在 Android Studio 中导入 Cordova 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24936689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import Cordova project in Android Studio
提问by andrei
I am trying to create a Cordova project. After creating the project cordova create myProject
I would like to open it in Android Studio. The problem is ... it doesn't work.
我正在尝试创建一个 Cordova 项目。创建项目后,cordova create myProject
我想在 Android Studio 中打开它。问题是......它不起作用。
The CordovaLib will not build with various errors package android.* does not exist
.
CordovaLib 不会因各种错误而构建package android.* does not exist
。
Does anyone know how to import a cordova project in Android Studio?
有谁知道如何在 Android Studio 中导入科尔多瓦项目?
回答by Ryan Knell
Unfortunately the accepted answer is a bit out of date. Using Cordova v5.3.3 (it probably works on all versions > 5) it is much the same process a building and then entering XCode for an iOS application now - the build system has moved to gradle.
不幸的是,接受的答案有点过时了。使用 Cordova v5.3.3(它可能适用于所有版本 > 5),它与构建然后为 iOS 应用程序输入 XCode 的过程大致相同 - 构建系统已转移到 gradle。
Before opening in Android Studio
在 Android Studio 中打开之前
cordova build android
Then just open up the project using File > Open and pointing to the (yourProjectDir)/Platforms/Androiddirectory.
然后使用 File > Open 打开项目并指向(yourProjectDir)/Platforms/Android目录。
If you are using an older version of the cordova android platform you might need to run
如果您使用的是旧版本的cordova android 平台,则可能需要运行
cordova platform android update
To get moved to the gradle build system which is compatible with the current version of Android Studio
转移到与当前版本的 Android Studio 兼容的 gradle 构建系统
回答by Kris Erickson
Make sure you import the "platform/android" directory underneath your cordova project (and you want to Import Project, not Open Project).
确保在cordova 项目下导入“platform/android”目录(并且您要导入项目,而不是打开项目)。
You will at least need to run
你至少需要运行
cordova prepare android
before doing the import
在做导入之前
cordova build android
will also work, but it will create some ant directories which will not be used by Android Studio and you will have to actively ignore the files when importing otherwise you will get extra libraries in your project). Although I haven't imported a Cordova app into android studio recently, it definitely works in the Community edition of Intellijwhich Android Studio is based on (I did it yesterday with a project built from scratch with Cordova 3.5). I can't think of any of the additional features in Android Studio that would be useful that aren't in Intellij, as most of the additions which haven't been backported to Intellij are in the preview space which isn't going to work with Cordova anyway (all it is going to preview is a blank webkit view).
也可以工作,但它会创建一些 Android Studio 不会使用的 ant 目录,您在导入时必须主动忽略这些文件,否则您将在项目中获得额外的库)。尽管我最近没有将 Cordova 应用程序导入 android studio,但它确实可以在Android Studio 所基于的Intellij社区版中使用(我昨天使用 Cordova 3.5 从头开始构建了一个项目)。我想不出 Android Studio 中没有 Intellij 中没有的任何有用的附加功能,因为大多数尚未向后移植到 Intellij 的附加功能都在预览空间中,这些功能将不起作用无论如何都要使用 Cordova(它要预览的只是一个空白的 webkit 视图)。
回答by iOSAndroidWindowsMobileAppsDev
All the answers above seem to refer to the cli. However, to actually have your project in android studio so that you can harness the power of the android studio, this is what I would suggest you do:
上面的所有答案似乎都参考了 cli。但是,要在 android studio 中实际拥有您的项目,以便您可以利用 android studio 的强大功能,我建议您这样做:
Please see my most relevant answer here...
请在此处查看我最相关的答案...
回答by Marcelo Tadeu
We have some troubles on importing Ionic project to android studio because we have add android platform with SUDO command, and because of it, android studio dont have access privileges to read files.
In my case just do sudo chmod -Rf 777 ionicFolder
android studio can import project successful.
I hope this help some one with this problem.
我们在将 Ionic 项目导入 android studio 时遇到了一些麻烦,因为我们使用 SUDO 命令添加了 android 平台,因此,android studio 没有读取文件的访问权限。在我的情况下,只要做sudo chmod -Rf 777 ionicFolder
android studio 就可以成功导入项目。我希望这可以帮助解决这个问题的人。