【问题标题】:Migrating Library and Apps from Eclipse to Android Studio将库和应用程序从 Eclipse 迁移到 Android Studio
【发布时间】:2015-04-26 08:35:25
【问题描述】:

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

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

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

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

将Eclipse项目直接导入Studio

此选项有效,但:

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

  2. 如果我们想添加一个临时项目以使用我们的库对其进行测试,我们需要导入它,以便它也将被复制到“主”库和演示旁边。

    李>

从 Eclipse 中将 Eclipse 项目导出为 Gradle 项目。

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

错误:失败:构建失败并出现异常。 * 出了什么问题:任务 在项目“:TestMemCons”中找不到“compileDebugSources”。 * 尝试:运行 gradle tasks 以获取可用任务的列表。使用 --stacktrace 运行 获取堆栈跟踪的选项。使用 --info 或 --debug 选项运行以 获取更多日志输出。

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

【问题讨论】:

    标签: android eclipse android-studio adt


    【解决方案1】:

    回答我自己的问题...

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

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

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

    • 将测试项目的相对路径添加到主项目的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 中删除测试条目,并删除测试项目文件夹以使主项目像测试前一样干净。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多