2015-02-24 88 views
1

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

由于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项目在相同的情况下,使他们可以参考我们的图书馆项目?

回答

1

回答我的问题...

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中删除测试条目,并删除测试项目文件夹以使测试前的主项目变得干净。
相关问题