5

So, we have been migrating from Eclipse to the new Android Studio IDE (knowing that it's an early release version). Everything was splendid until yesterday when we updated to 0.1.1, which removed the Project Structure UI interface, replacing it with a message telling us to use gradle.

So we began reading documentation, SO posts and watched the Google I/O presentation. We still don't understand how this works.

We've read this user guide and, like I said, countless SO posts. But can't get this to work.

So we have 2 projects. Both of them are Android projects. Both use external projects. One of them uses the Facebook Android SDK and the other uses a custom, straight up java project. The java project is continually being updated.
The java project was created in Eclipse and has that folder structure.
Both of the Android Projects were created fresh in Android Studio. How do we do this?

Do the library projects need their own build.gradle files?
Do the library projects need to be placed in the same folder as our Android Projects?

And depending on the answer to those questions, how do the build.gradle and settings.gradle files need to look?

[EDIT]
For clarification:

Facts:
Android Project A needs to use the Facebook SDK external library
Android Project B needs to use an external java project I created in Eclipse
Projects A and B were both created in Android Studio

Questions:
● What needs to go into Project A build.gradle file?
● Where does the Facebook SDK need to be?
● Does the Facebook SDK need a build.gradle file? If so, what does it need to say?

● What needs to go into Project B build.gradle file?
● Where does the java project need to go?
● Does this java project need a build.gradle file? If so, what does it need to say?

● Does the Facebook SDK or the java project need a settings.gradle file?

Bjorninn
  • 4,027
  • 4
  • 27
  • 39

2 Answers2

0

Each project, module or library you compile need a build.gradle file.

The most simple Android project has the following build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.3'
    }
}

apply plugin: 'android'

android {
    compileSdkVersion 17
}

If you imported a project from eclipse, you should add that lines to match the project structure :

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aild.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
    }
}

You can add dependencies from other project or file like that :

dependencies {
    compile file('libs/adnroid-support-v4.jar')
    compile project(':libraries:actionbarsherlock')
}

For more informations, you can have a look at the documentation here.

Rémi F
  • 1,327
  • 12
  • 25
  • Well like I said I've already read that documentation. The code above is just copy-paste from that. I still have no idea how to structure the projects. I can import Eclipse project into AS and run them without having any build.gradle files, that's just not recommended. – Bjorninn May 30 '13 at 14:13
  • It also says: "This is Android specific and will not work on Java sourceSets." – Bjorninn May 30 '13 at 14:26
  • 1
    sourceSet closure has to be inside android, otherwise it is considered to be java plugin closure – robotoaster Jul 01 '13 at 08:34
  • Your solution states that if I have two projects which uses the actionbarsherlock, that I must have two copies of the actionbarsherlock project as a subfolder in each of them. I think the main question here is what I'm trying to understand here: http://stackoverflow.com/questions/17479076/android-studio-add-external-project-to-build-gradle – TacB0sS Jul 05 '13 at 12:08
  • I think you can refer to external folder. For example '../../libraries/ABS'. Perhaps you can use a complete path. – Rémi F Jul 15 '13 at 18:48
0

go to http://tools.android.com/tech-docs/new-build-system, download zip from the bottom of the page named gradle-samples-0.4.2.zip

check libsTest example

After you setup gradle build files you need to do extra hoop for Android Studio as it doesn't pickup changes from build.gradle

robotoaster
  • 3,082
  • 1
  • 24
  • 23