[英]Import from Eclipse to Android Studio not working
我已采取以下步驟遷移到Android Studio,但現在我不知道出了什么問題。
結果:build.gradle文件中的大多數內容都顯示為灰色,告訴我它無法解析符號[name]。 當我構建時,我有超過100個錯誤,所有錯誤都與不存在的依賴關系有關(gradle沒有做它的工作)。 此外,我在過去幾天一直在使用gradle項目,該文件通常總是要求同步,並在構建項目之前構建gradle文件。 在我的情況下,沒有那個。 這就像我的項目不知道他需要使用gradle或gradle沒有正確配置。 這是我的gradle文件和一些截圖,以幫助您了解我的問題。 任何幫助表示贊賞。
的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "XXXXXX"
minSdkVersion 15
targetSdkVersion 15
testApplicationId "XXXXXXX"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
packagingOptions {
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
dependencies {
compile group: 'com.google.android', name: 'android', version: '4.1.1.4' //provided
compile group: 'org.springframework.android', name: 'spring-android-core', version: '1.0.1.RELEASE'
compile group: 'commons-io', name: 'commons-io', version: '1.4'
compile group: 'org.springframework.android', name: 'spring-android-rest-template', version: '1.0.1.RELEASE'
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'
compile group: 'com.google.code.gson', name: 'gson', version: '2.3'
compile group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.3.0'
compile group: 'joda-time', name: 'joda-time', version: '2.3'
compile group: 'net.erdfelt.android', name: 'apk-parser', version: '1.0.2'
compile group: 'org.apache.commons', name: 'commons-compress', version: '1.9'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.8'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.6.1'
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.6.1'
}
android studio中的外觀截圖:
Android視圖中沒有gradle子文件夾? 這是正常的嗎?!
謝謝!
編輯我確實喜歡在評論中建議。 我似乎更進一步,但我收到消息:“Gradle項目同步失敗。基本功能將無法正常工作”。 在下面的消息中,我有這個。 我能做什么?
Error:Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.
Possible causes for this unexpected error include:<ul><li>You are using JDK version 'java version "1.7.0_75"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.
Please update to a newer version (e.g. 1.7.0_67).
<a href="open.project.structure">Open JDK Settings</a></li><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
如果這可以幫助那里的任何人,這里是我執行遷移的步驟。
導出build.gradle文件
將Maven依賴項轉換為gradle
如果您使用的是Maven依賴項,那么所有依賴項都是這樣的:
<dependency>
<groupId>org.springframework.android</groupId>
<artifactId>spring-android-core</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>
您需要將其轉換為以下格式:
dependencies {
compile group: 'com.google.android', name: 'android', version: '4.1.1.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
如您所見,如果需要編譯依賴項,請將關鍵字“compile”放在其前面。 如果是測試,請使用關鍵字“testCompile”。 暫時將其保存在臨時文件中。
安裝Android Studio並對其進行配置從以下位置安裝Android Studio: http : //developer.android.com/sdk/index.html下載/安裝時,打開以前生成的build.gradle文件並更改以下內容。 更換
apply plugin: 'android'
同
apply plugin: 'com.android.application'
確保你的“buildScript”代碼塊看起來像那樣
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
最后,在android代碼塊之外添加存儲庫和依賴項信息。
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.android:android:4.1.1.4'
...
}
現在安裝了Android Studio,打開它。 選擇“導入項目(Eclipse ADT,Gradle等)”並導航到build.gradle文件。 Android Studio現在應該創建運行項目所需的所有元數據和文件。 如果計算機上的工具版本出現錯誤,請返回Android Studio的簡介屏幕並選擇“配置/ SDK管理器”。 下載項目工作所需的一切。 在項目中,進入“文件/項目結構”。 在項目選項卡中,確保gradle版本是2.2.1並且android插件是1.1.0。 下一步應該是創建配置並在可用的USB設備或仿真器上運行它。
你已准備好出發!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.