如何获取的PhoneGap项目在Android的Studio中运行与摇篮构建系统 [英] How to Get a PhoneGap Project to Run in Android Studio with Gradle Build System

查看:504
本文介绍了如何获取的PhoneGap项目在Android的Studio中运行与摇篮构建系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个新的PhoneGap应用程序设置和内部的Andr​​oid Studio中运行的摇篮构建系统。

I'm trying to get a new PhoneGap application setup and running inside Android Studio with the Gradle build system.

目前,我已经成功地创建了PhoneGap的项目,并导入到Android的工作室。这一切似乎都很正常的工作,但我不能工作,如何将其移动到摇篮构建系统,甚至如果可能的。

At the moment I have successfully created the PhoneGap project and imported into Android Studio. It all appears to be working fine, but I cant work out how to move it to the Gradle build system, or even if its possible.

有人能帮忙吗?

推荐答案

我成功地做到这一点。

您必须使用Android Studio和Eclipse的ADT版本,以及科尔多瓦/ PhoneGap的所有设置。

You need Android Studio and the Eclipse ADT version, as well as Cordova/PhoneGap all set up.

  1. 导入科尔多瓦项目到Eclipse中。
  2. 转到文件 - >导出... - >生成摇篮构建文件
  3. 单击旁边让过去的导入呢?屏幕。
  4. 选择两个你的Andr​​oid项目和CordovaLib项目导出,然后单击下一步。

  1. Import the Cordova project into Eclipse.
  2. Go to File -> Export... -> Generate Gradle Build Files.
  3. Click next to get past the "Import Instead?" screen.
  4. Select both your Android project and the CordovaLib project to export and click Next.

在此完成,开放的Andr​​oid工作室。

Once this completes, open Android Studio.

导入之后,你可能会获得有关新版本的摇篮在使用一些警告,只是检查你的设置,它似乎自己打工了。

After the import, you may get some warnings about a newer gradle version in use, just check your settings and it seems to work itself out.

在这一点上,你应该有一个项目的结构,它是你的主要项目,但CordovaLib作为一个模块。

At this point, you should have a project structure that is your main project, but with CordovaLib as a module.

现在,你可以在主项目目录中打开build.gradle文件,并将其改成这样:

Now you can open the build.gradle file in the main project directory and change it to this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.11.+'
    }
}

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':CordovaLib')
    compile 'com.android.support:appcompat-v7:19.+'
}

您现在应该能够说服Android的工作室进行编译。

You should now be able to convince Android Studio to compile.

这是额外的小费是创建一个脚本来运行科尔多瓦prepare,并添加到模块的运行配置为外部工具。 确保以整个项目部署APK设备或仿真器之前同步。

An extra tip would be to create a script to run "cordova prepare" and add that to the module's run configuration as an external tool. Make sure to synchronise the whole project before deploying the APK to a device or emulator.

这篇关于如何获取的PhoneGap项目在Android的Studio中运行与摇篮构建系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆