Cannot import Eclipse project into Android Studio - android

I'm trying to import an Android project build on Eclipse into my Android Studio IDE. I'm following the steps to import properly the project with a build.gradle file but when I'm trying to compile, I get this weird error: Plugin with id 'android' not found. I have this version of Android Studio: Android Studio (Preview) 0.4.3. Here is my build.gradle:
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':workspace:DesignDialogLibrary')
compile project(':workspace:HoloColorPickerLib')
compile project(':workspace:MbAdBleamSdkReaderLibrary')
compile project(':workspace:ViewPagerLibrary')
compile project(':workspace:PullToRefreshLibrary')
compile project(':workspace:SlidingMenuLib')
}
android {
compileSdkVersion 17
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']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}

You're missing this block in your build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
This block tells Gradle where to find the "android" plugin that you're missing.
It's standard in projects created in newer versions of Android Studio to put this in the build.gradle that's in your project's root directory and omit it from the one that's in your module's directory, so look there and see if looks like it's in order.
If you don't have that root-level build.gradle file and you've only got one directory and one build file, then add this block to that file. Be aware, however, that Android Studio currently has a few bugs that prevent the Project Structure dialog from working properly with projects in this single-module format, though I believe they'll otherwise build and run fine.

Related

Gradle apk file missing dependencies

I am new to Gradle. I have been looking for a solution to my problem for several hours now but cannot get my build to work correctly. Basically I have an Android project that I am trying to build using Gradle. I have a libs directory in my project that contains dependencies. It appears the build knows that they are there because it uses them when compiling the application. However, when the apk is assembled the dependencies are not in the apk. I am trying to get this to generate an apk file that is similar to the apk that is generated when you perform an Export from MyEclipse. The apk generated from the MyEclipse export has a lib directory as well as an org directory so I know the dependencies are in that apk. The apk generated from Gradle has neither. Here is my build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion "23.0.2"
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}

Not able to upload the generated .aar file to local maven repository in android studio with gradle build dystem

I am using android studio with Gradle as build system. I have a library project and application project.
Library - library project.
Application - application project
Gradle and android studio generates .aar files instead of .jar files.
So I wanted to add generated .aar file as a dependency to my application project.
Since there is no support from android studio and gradle wrapper to add .aar files as a dependency for application project, I have tried to upload the .aar file to local maven repository.
The build.gradle code to upload the .aar file to local maven repository is below.
apply plugin: 'maven'
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 21
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']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
repositories {
mavenLocal()
}
configurations {
resultArchives
}
uploadResultArchives {
repositories {
mavenDeployer {
repository(url: 'C:/Users/test/.m2/repository')
}
}
}
artifacts{
resultArchives file: file('build/output/aar/Library-debug.aar')
}
Setup info: Android studio1.1.0
Gradle wrapper: 2.2.1
Thanks in advance for your help!!!
I'm not a gradle pro. But I think this will work:
group = 'Library-debug'
uploadArchives{
repositories{
mavenDeployer{
repository(url: uri('C:/Users/test/.m2/repository'))
}
}
}
Your aar will be available on "C:/Users/test/.m2/repository/[your package name]/Local-debug.aar"

Add Cardslib library To Android Studio 0.8.1

This is my first project using Android Studio so spare me if you find this question naive. I am trying to include the Cardslib library to my project in Android Studio (version 0.8.1). Initially I tried to include it by adding the following line in build.gradle:
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
But it returned the following error (upon sync)
Error:Failed to find: com.github.gabrielemariotti.cards:library:1.7.3
The I tried to include the jar file by,
Downloading it from maven repository
Adding jar file to libs folder.
Adding following line in build.gradle
compile files('libs/library-1.7.3-sources.jar')`
Though gradle project sync without any error but I am not able to create simple cards i.e still not working for me.
I wanted the first method to work since Android Studio would then handle everything but I guess I am doing something horribly wrong.
[Edit] - Adding the build.gradle code
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
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')
}
}
Add this block in your script to tell gradle where it can find the repo with libs.
repositories {
mavenCentral()
}
So your script will be something like this:
.......
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
}
.......

Eclipse exported project in Android Studio and add remote dependency in build.gradle

I have exported my Android project in Eclipse as gradle build files, and imported in Android Studio.
I have updated my Android Studio today to v0.6.0 which built on June 05, 2014.
As a remote dependency I have added AppCompat to the dependencies which works fine as expected.
compile 'com.android.support:appcompat-v7:19.+'
But when I try to add other libraries such as SmoothProgressBar, actionbarsherlock, nineoldandroids and etc, it fails. When I run the app it shows following in Gradle Build tab:
Error:A problem occurred configuring root project 'MyApp'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
> Could not find com.github.castorflex.smoothprogressbar:library:0.5.1.
Required by:
:MyApp:unspecified
And when I sync project with Gradle file, it shows following in Gradle Sync tab:
Error:com.github.castorflex.smoothprogressbar:library:0.5.1 (double-click here to find usages.)
I tried an empty new project and add remote dependency for mentioned libraries(Sherlock and etc) worked as expected. So I guess I missed something in build.gradle or any other solution?
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.castorflex.smoothprogressbar:library:0.5.1'
compile 'com.android.support:appcompat-v7:19.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
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')
}
}
Add this code to your build.gradle
repositories {
mavenCentral()
}
Update to explain the answer:
To resolve your dependencies, you have to indicate in the gradle script which are the repositories to be used. You can use more repositories...
With the support libs (support and support-compact) it is not necessary, because the android plugin searches in your androidRepository and googleRepository downloaded with your SDK Manager.

Gradle import issues - Android

I am currently attempting to switch my project over to using gradle builds. While using the old build system I linked to the private/internal/hidden android API's by compiling the source and linking the classes.jar files before the Android libraries. I am currently trying to do the same thing in gradle with no luck at all.
With my current build.gradle file I receive the following error:
Gradle: A problem occurred evaluating project ':Launcher2'.
> Could not find method external() for arguments [file collection] on project ':Launcher2'.
If I remove these lines before "apply plugin: android"
dependencies {
compile files('libraries/classes.jar')
}
I receive errors about missing com.android.internal and com.android.common packages which are located in my classes.jar file.
Here's my build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
dependencies {
compile files('libraries/classes.jar')
}
plugin: 'android'
android {
buildToolsVersion "17.0"
compileSdkVersion 10
dependencies {
compile fileTree(dir: 'libraries', include: '*.jar')
compile project(':ActiveAndroid')
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Edit: After reading the gradle documentation a bit more I was able to successfully link the libraries into the project but the order of dependencies is wrong. The equivalent to what I am trying to do is adding both .jar files to the top of the classpath so that they are declared before the android SDK jar files.
I was digging through the source for the android gradle plugin, it seems that this may not be possible. The code seems incomplete and will not build. If anyone has any insight I would really appreciate it. Otherwise it looks like I will have to switch back to using Ant for now.

Categories

Resources