简体   繁体   English

如何在Android Studio 0.5.4中使用PhoneGap?

[英]How to use PhoneGap with Android Studio 0.5.4?

Can anybody tell me how get Android Studio 0.5.x to properly import and build a PhoneGap project ? 谁能告诉我如何让Android Studio 0.5.x正确导入和构建PhoneGap项目?

I've successfully installed the JDK SE 1.8.0, Ant 1.9.3, PhoneGap 3.4.0 and Android Studio 0.5.4. 我已经成功安装了JDK SE 1.8.0,Ant 1.9.3,PhoneGap 3.4.0和Android Studio 0.5.4。

JAVA_HOME , ANT_HOME , ANDROID_HOME are properly set, PATH was extended to include the %JAVA_HOME%\\bin as well as %ANDROID_HOME%\\tools and %ANDROID_HOME%\\platform-tools . 正确设置了JAVA_HOMEANT_HOMEANDROID_HOME ,扩展了PATH以包含%JAVA_HOME%\\bin以及%ANDROID_HOME%\\tools%ANDROID_HOME%\\platform-tools

I can create a PhoneGap hello-world project as outlined here: http://phonegap.com/install/ 我可以创建一个如下所述的PhoneGap hello-world项目: http//phonegap.com/install/

The vanilla hello-world project as is will build and run with the configured AVD: 这个vanilla hello-world项目将使用配置的AVD 构建和运行

phonegap run android --emulator

However, when I try to import the project according to this tutorial into Android Studio 0.5.4 , it won't compile. 但是,当我尝试根据本教程将项目导入Android Studio 0.5.4时 ,它将无法编译。

First, import in 0.5.4 is entirely different from what is shown on the linked page, there are none of the presented options (you can only select the folder from which to import, the destination directory, and whether to "Replace jars with dependencies, when possible" / "Replace library sources with dependencies, when possible" and "Create Gradle-style (camelCase) module names", all selected by default). 首先,0.5.4中的导入与链接页面上显示的内容完全不同 ,没有显示的选项(您只能选择要导入的文件夹,目标目录以及是否“替换带有依赖项的jar文件夹” ,如果可能的话“/”替换具有依赖关系的库源,如果可能的话“和”创建Gradle-style(camelCase)模块名称“,默认情况下全部选中)。

Android Studio shows errors such as these: Android Studio会显示以下错误:

Error:(19, 26) error: package android.annotation does not exist
Error:(26, 16) error: package org.json does not exist
Error:(30, 23) error: package android.content does not exist

However, I do see < Android API 19 Platform > and < JDK > in the External Libraries section, with android.jar and annotations.jar and eg android.annotation in there. 但是,我确实在外部库部分看到了< Android API 19 Platform >< JDK > ,其中包含android.jarannotations.jar以及android.annotation

I tried to set minSdkVersion 19 for project helloWorld but this didn't fix anything. 我试图为项目helloWorld设置minSdkVersion 19 ,但这并没有解决任何问题。

I've faced this same issue, except it's been with Cordova rather than PhoneGap. 我遇到过同样的问题,除了Cordova而不是PhoneGap。 I'm unaware of what needs changing in the Android project to have it work in Android Studio (or Eclipse - found issues with both). 我不知道Android项目需要改变什么才能让它在Android Studio(或Eclipse中找到问题)中发挥作用。

Instead I started to play around with versions. 相反,我开始玩版本。 It looks like the error that occurs with Cordova version 3.5.0-0.2.4 doesn't occur with Cordova version 3.0.0. 看起来Cordova版本3.0.0不会出现Cordova版本3.5.0-0.2.4时出现的错误。 It's now building and running fine for me. 它现在正在为我建造并运行良好。

Getting an older Cordova version is simple, if on Mac OS X/*nix: 如果在Mac OS X / * nix上获得较旧的Cordova版本很简单:

sudo npm install -g cordova@3.0.0

I suspect there is some sort of bug/inconsistency with the later Cordova versions. 我怀疑后来的Cordova版本存在某种错误/不一致。 Note I chose v3.0.0 simply because I wasn't able to do the above for v3.1+. 注意我选择v3.0.0只是因为我无法对v3.1 +进行上述操作。

If I get more time later on, I'll try analyse the differences between the 3.0.0 build and the 3.5.0 build. 如果我以后有更多的时间,我会尝试分析3.0.0版本和3.5.0版本之间的差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM