2015-02-24 86 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中刪除測試條目,並刪除測試項目文件夾以使測試前的主項目變得乾淨。
相關問題