android - 将库和应用程序从 Eclipse 迁移到 Android Studio

标签 android eclipse android-studio adt

在我的团队中,我们使用 ADT 插件在 Eclipse 中开发了一个库。
我们有一个“大”演示应用程序和几个使用该库测试不同方面的“迷你”应用程序。

由于 Android 的官方 IDE 现在是 Android Studio,而且 ADT 插件似乎已被放弃(last update on October '14),我们正在研究向 Android Studio 的迁移。

在 Eclipse 上,我们可以在同一工作区内从磁盘中的不同位置加载项目。我们喜欢这个,因为这允许我们将我们的库项目与我们的演示一起加载,我们还可以在引用项目库的同一工作区中加载临时项目。

我看到有 two ways to migrate ,但我发现两者都有缺点:

Importing the Eclipse project directly into Studio

此选项有效但是:

  1. 这会更改所有项目的文件夹结构。它将 eclipse 项目复制到 Android Studio 项目文件夹中,这意味着对我们的内部存储库进行更改。

  2. 如果我们想添加一个临时项目来用我们的库测试它,我们需要导入它,这样它也会被复制到“主”库和演示旁边。

    <

Exporting the Eclipse project from Eclipse as a Gradle project.

此选项保留我们的 Eclipse 项目的文件夹结构(上面的#1),但上面的#2 在这里仍然有效,当我尝试从其他位置导入项目时,我也会遇到此错误。

Error:FAILURE: Build failed with an exception. * What went wrong: Task 'compileDebugSources' not found in project ':TestMemCons'. * Try: Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

那么,我们能否迁移到 Android Studio 并保持文件夹结构并允许我们在同一实例中加载其他 Eclipse/Android Studio 项目,以便它们可以引用我们的库项目?

最佳答案

回答我自己的问题...

So, can we migrate to Android Studio keeping the folder structure and allowing us to load other Eclipse/Android Studio projects in the same instance so they can reference our library project?

我发现您可以按如下方式添加时间项目:

  • 将临时测试项目复制到您想要的位置,它只需位于您的主项目树中即可。

  • 将测试项目相对路径添加到主项目的settings.gradle文件中。即,如果您将测试项目移动到 \Demos\Tests\Test1:

    include ':Demos:Tests:Test1'
    

所以你可以有这样的东西:

    include ':Sources:Android'   //library
    include ':Demos:Android'     //Features Demo
    include ':Demos:Tests:Test1' //Test1
  • 为测试项目创建一个build.gradle 文件。即,\Demos\Tests\Test1\build.gradle:

    apply plugin: 'android'
    
    dependencies {
        compile fileTree(include: '*.jar', dir: 'libs')
        compile project(':Sources:Android')
    }
    
    android {
        compileSdkVersion 7
        buildToolsVersion "21.1.2"
    
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }
    
            // Move the tests to tests/java, tests/res, etc...
            instrumentTest.setRoot('tests')
    
            // Move the build types to build-types/<type>
            // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
            // This moves them out of them default location under src/<type>/... which would
            // conflict with src/ being used by the main source set.
            // Adding new build types or product flavors should be accompanied
            // by a similar customization.
            debug.setRoot('build-types/debug')
            release.setRoot('build-types/release')
        }
    }
    

在这种情况下,我向我的库添加了一个依赖项,即位于 \Sources\Android 的主项目中的一个库模块。

因此,如果您想保留您的文件夹结构,您可以选择选项 2“将 Eclipse 项目从 Eclipse 导出为 Gradle 项目”,并仍然如上所述加载测试/临时项目。

我在这里看到的唯一问题是:

  • 这不像 Eclipse 那样自动。
  • 在 Eclipse 中,您可以在完成后删除测试项目,该项目仍在磁盘中,但工作区再次干净。在 Android Studio 中,使用上述技术,您应该从主项目的 settings.gradle 中删除测试条目,并删除测试项目文件夹以使主项目像测试前一样干净。<

关于android - 将库和应用程序从 Eclipse 迁移到 Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28700572/

相关文章:

C++ - getline stdin EOF 不工作

android - 使所有 fragment 位于横幅广告上方

java - Android Studio : Read in a text file, 在弹出窗口中显示

java - 变量可能未初始化错误

c - 使用 fopen,c\ubuntu 打开文件

java - 编辑文本中不显示字符串

android studio ctrl + space 打开文档窗口

android - 更改 LayoutParams 后,RelativeLayout 中的按钮消失

java - Android 客户端上的 SSL 相互身份验证失败客户端接受服务器证书但服务器未获得客户端证书

java - 尝试在空对象引用上调用虚拟方法 'void ListView.setAdapter(ListAdapter)'