I have taken the following steps to migrate to Android Studio but right now I don't know what is wrong.
Results: Most of the content in the build.gradle file is grayed out, telling me it cannot resolve symbol [name]. When I build, I have more than 100 errors, all of them related to dependencies not present (gradle not doing it's job). Also, I have been using gradle project in the last couple of days and the file is normally always asking to sync and it build the gradle file before building your project. In my case, nothing of that. It's like my project don't know he needs to use gradle or gradle is not configured the right way. Here is my gradle file and some screenshot to help you understand my problem. Any help is appreciated.
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'
}
Screenshot of what it looks like in android studio:
No gradle subfolder in Android View? Is it normal?!
Thank you!
EDIT I did like suggested in the comment. I seem to be a step further but I'm having the message: "Gradle project sync failed. Basic functionality will not work properly". In the message below, I have this. What can I do?
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.
If this can help anyone out there, here are the steps I followed to do the migration.
Exportation of the build.gradle file
Converting Maven dependencies to gradle
If you are using Maven dependencies, all of your dependencies looks like that:
<dependency>
<groupId>org.springframework.android</groupId>
<artifactId>spring-android-core</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>
You need to convert it to this format:
dependencies {
compile group: 'com.google.android', name: 'android', version: '4.1.1.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
As you can see, if the dependency is needed to compile, put the keyword "compile" in front of it. If it's for the testing, use the keyword "testCompile". Keep that in a temporary file for the moment.
Installing Android Studio and configuring it Install Android Studio from this location: http://developer.android.com/sdk/index.html While it download/install, open your previously generated build.gradle file and change the following things. Replace
apply plugin: 'android'
With
apply plugin: 'com.android.application'
Be sure that your "buildScript" code-block looks like that
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
Finally, add the repositories and dependencies information outside of the android code block.
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.android:android:4.1.1.4'
...
}
Now that Android Studio is installed, open it. Choose "Import Project (Eclipse ADT, Gradle, etc)" and navigate to the build.gradle file. Android Studio should now create all the metadata and file needed to run the project. If there is an error regarding the version of the tool on your compute, go back to the intro screen of Android Studio and choose "Configure/SDK Manager". Download whatever is necessary for your project to work. When in the project, Go in "File/Project Structure". In the project tab, be sure that the gradle version is 2.2.1 and that the android plugin is 1.1.0. The next step should be to create a configuration and run it on the USB device available or Emulator.
You are good to go!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments