我有一個已經在Android Studio中運行的項目。無法將項目遷移到Android Studio中的Gradle
我已經打開Android Studio中的項目後,我得到的消息:
移植項目到搖籃? 該項目不使用Gradle構建系統。我們建議您遷移到使用Gradle構建系統。 有關遷移到Gradle的更多信息 不再顯示此消息。
繼More Information about migrating to Gradle的鏈接,雖然我已經在Android Studio
我按照選項Migrating from IntelliJ Projects。
由於我已經在我的項目的根目錄下有一個build.gradle
文件,所以我修改了它以包含一些依賴關係。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile "com.android.support:support-v4:18.0.+"
compile "com.android.support:appcompat-v7:18.0.+"
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
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')
}
}
按照指示,我已經跑了Android Studio
終端窗口gradle assembleDebug
但得到了一些錯誤。爲了解決這個錯誤,我必須創建一個local.properties
和sdk.dir=C:\\Program Files (x86)\\Android\\android-sdk
,並從/libs
文件夾中刪除android-support-v4.jar
文件,並從Project Structure
中刪除Libraries->libs
。
我現在再次運行gradle assembleDebug
,這一次它完成沒有任何錯誤。
我已經重新啓動Android Studio
但在重新啓動後,我已經看到了該項目的External Libraries
沒有support-v4
和appcompat-v7
,在我班的一個我自Cannot resolve symbol Cursor Adapter
標記爲錯誤import android.support.v4.widget.CursorAdapter;
。
如果我按下按鈕Sync project with gradle files
我得到的消息:The project MyProject is not a Gradle-based project
誰能幫我搞清楚如何解決這個問題?
這裏是我的項目結構
嘗試'文件>無效緩存/重啓',並檢查你是否得到相同的錯誤。請將您的項目結構包括在內,以便更好地理解問題。 – pyus13
增加了結構,但是'File> Invalidate Caches/Restart'沒有做任何事情 – Favolas