如何建立与Android Studio和摇篮的机器人库?摇篮、机器人、Android、Studio

2023-09-12 21:33:07 作者:只藏于心、不表于情

我试图将项目从Eclipse的迁移,但没有我曾尝试在工作。在Eclipse我有3个项目(2 Android应用程序项目和1个机器人库项目)。 2.应用项目依赖于库项目。当我做出口的摇篮,我得到3个项目,不工作。我打开重组项目,但还没有找到这个应该怎么做任何文件。

I am trying to migrate a project from Eclipse but nothing I have tried is working. In Eclipse I have 3 projects (2 android app projects and 1 android library project). The 2 app projects depend on the library project. When I do the gradle export I get 3 projects that don't work. I am open to restructuring the project but haven't found any documentation on how this should be done.

有没有一种方法,使3个项目是Eclipse的出口协同工作?我是最好的重组的事情,如果是这样的文档,这个应该怎么做?

Is there a way to make the 3 projects that Eclipse exports work together? Am I better off restructuring things and if so is documentation for how this should be done?

更新

我已经上传了整个项目的GitHub https://github.com/respectThe$c$c/android-studio-library-example

I have uploaded the entire project to GitHub https://github.com/respectTheCode/android-studio-library-example

更新1

根据从帕德玛·库马尔的建议,这是我都试过了。

Based the suggestions from Padma Kumar this is what I have tried.

创建一个新的项目名为的MyApp 点击文件>新模块,选择的Andr​​oid库并将其命名为 MyLib中 点击构建>使项目 Create a new Project called MyApp Click File > New Module, choose Android Library and name it MyLib Click Build > Make Project

构建失败,此错误

Module "MyLib" was fully rebuilt due to project configuration/dependencies changes
Compilation completed with 1 error and 0 warnings in 19 sec
1 error
0 warnings
/.../MyApp/MyLib/build/bundles/debug/AndroidManifest.xml
Gradle: <manifest> does not have package attribute.

然后我加了属性清单使它

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mylib" >

建立之后,我得到这个错误

After building I get this error

Module "MyApp" was fully rebuilt due to project configuration/dependencies changes
Compilation completed with 2 errors and 0 warnings in 13 sec
2 errors
0 warnings
/.../MyApp/MyLib/src/main/java/com/example/mylib/MainActivity.java
Gradle: package R does not exist
Gradle: package R does not exist

添加依赖似乎并没有对错误的任何影响。从上面继续

Adding dependency doesn't seem to have any impact on the error. Continuing from above

点击文件&gt;项目结构&gt;模块&gt; MyApp的-的MyApp 切换到依赖标签 点击 +&GT;模块依赖并选择 MyLib中 点击应用确定 点击构建&GT;使项目 Click File > Project Structure > Modules > MyApp-MyApp Switch to Dependencies Tab Click + > Module Dependency and pick MyLib Click Apply and OK Click Build > Make Project

更新2

根据从伊森的建议,这是我们得到

Based the suggestions from Ethan this is where we get

在2分项目 build.gradle 似乎有所有正确的部分,唯一的区别是插件线波纹管是 MyApp的/ build.gradle

The 2 sub project build.gradle seem to have all of the correct parts and the only difference is the plugin line bellow is the MyApp/build.gradle.

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

所以我加了两个项目这样的

根项目 build.gradle 是空

The root project build.gradle was empty so I added the two projects like this

dependencies {
    compile project(":MyLib")
    compile project(":MyApp")
}

我现在正在建设的时候得到这个错误

I now get this error when building

Gradle:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/kevin/GitHub/AppPress/MyApp/build.gradle' line: 2
* What went wrong:
A problem occurred evaluating root project 'MyApp'.
> Could not find method compile() for arguments [project ':MyLib'] on root project 'MyApp'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

更新3

非常感谢阮经天为解决这一点。

Big thanks Ethan for solving this.

添加编制项目(:子项目:MyLib中') MyLib中/ build.gradle 删除编译文件(库/ Android的支持 - v4.jar') MyLib中/ build.gradle 从摇篮关闭项目,并导入根项目 Add compile project(':SubProjects:MyLib') to the MyLib/build.gradle Remove compile files('libs/android-support-v4.jar') from the MyLib/build.gradle Close project and Import the root project from gradle

更新4

截至0.1.2,你现在可以包括编译com.android.support:support-v4:13.0.0而不是编译文件(库/ Android的支持 - v4.jar')。由于它是从mavin来了,现在你可以将此在多个项目中没有问题。

As of 0.1.2 you can now include compile "com.android.support:support-v4:13.0.0" instead of compile files('libs/android-support-v4.jar'). Since it is coming from mavin now you can include this in multiple projects without problems.

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.2'
    }
}

apply plugin: 'android'

dependencies {
    compile "com.android.support:support-v4:13.0.0"

    compile project(':SubProjects:MyLib')
}

更新5

由于0.1.3现在有工具栏中的同步工程按钮。您可以点击,而不是更改为 .gradle 文件后重新导入您的项目。

As of 0.1.3 there is now a "Sync Project" button in the toolbar. You can click that instead of reimporting your project after making changes to .gradle files.

推荐答案

注意:这个答案是一个纯粹的摇篮答案,我用这个在的IntelliJ定期,但我不知道该怎么整合与Android的工作室。我在知道是怎么回事,我的信徒,所以这是我如何使用摇篮和Android。

Note: This answer is a pure Gradle answer, I use this in IntelliJ on a regular basis but I don't know how the integration is with Android Studio. I am a believer in knowing what is going on for me, so this is how I use Gradle and Android.

TL; DR 完整的例子 - https://github.com/ethankhall/driving-time-tracker/

免责声明:这是一个项目,我/正致力于

Disclaimer: This is a project I am/was working on.

摇篮有href="http://tool​​s.android.com/tech-docs/new-build-system/user-guide">定义结构的