Android Studio 2.2導入eclipse版Android工程

最近研究FTDI的USB串口設備,下載了其Android版工程,解壓發現是eclipse開發的,用Android Studio導入,報以下錯誤:

Error:(16, 0) Could not find method android() for arguments [build_72neqfedty1a7qila40o6thc6$_run_closure2@7dda96d8] on root project 'TN_147_Java_D2xx_for_Android_Demo_Source' of type org.gradle.api.Project.
<a href="openFile:/home/haipeng/projects/TN_147_Java_D2xx_for_Android_Demo_Source/build.gradle">Open File</a>

去網上搜索正確的導入方法,結果都是需要先在eclipse下導出Gradle格式的工程,然後再在Android Studio下導入,這麼麻煩我還不如就用eclipse跑呢!

安裝Android版eclipse,導入工程後發現連下載配置項都沒有,真坑,於是決定還是沉下心來解決怎麼解決Android Studio的導入錯誤

在SOF上找到這篇帖子,看了下,原來是Android Studio導入eclipse工程時只生成了一個build.gradle文件,且內容既有project級別的內容,也有module級別的內容,導致gradle編譯失敗。

將默認生成的build.gradle文件中的android區塊刪除,然後重新sync,這時gradle就能正常工作,並且module級別的build.gradle文件也會自動生成,工程編譯通過!

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

//android {
//    defaultConfig {
//        minSdkVersion 10
//        targetSdkVersion 22
//    }
//    productFlavors {
//    }
//}
//dependencies {
//}

這個特性我只在Android Studio 2.2上測試過,更新的版本應該也可以。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章