I created new project in Android Studio in Ubuntu 12.04.
When the project opened, I can't config project structure. It says
We will provide a UI to configure project settings later. Until then,
please manually edit your build.gradle file(s.)
What can I do? I imported a eclipse project. IS it OK?
I can config project structure in Windows when I create a new project in Android Studio.
Not yet. Currently Android Studio follows (Google) Gradle Android project structure
so by default
<project root>
<src>
<main>
<java>
<res>
<instrumentTest>
<java>
<res>
If your project structure is different you can fiddle with it adding
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')
}
}
to match old project structure. For full documentation how to use gradle android plugin go
New Build System
Related
I am trying to import this library my Android Studio project, but am not having any luck because it doesn't have any gradle files. https://github.com/xibsked/android-numberpicker
I found these posts, (Using library products without gradle files in Android Studio, How to import project files without Gradle files into Android Studio) but they are either unanswered or the answers involve exporting from Eclipse, which isn't my case. I'm not migrating from Eclipse, just want to use this library.
Thanks!
That libary does appear to be published to Maven:
http://mvnrepository.com/artifact/net.simonvt/android-numberpicker/1.0.0
So you just need to add that dependency to your project's build.gradle file:
dependencies {
'net.simonvt:android-numberpicker:1.0.0'
}
If that's not an option for some reason, then you'll have to grab a copy of the source and import it into your project, as fractalwrench suggested.
in general you can do:
create a new module and copy the source in your project app/main/src
clone or copy the module library in your project and add the build.gradle file
In the second case just config the right source set in your build.gradle file
apply plugin: 'com.android.library'
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
In both scenario you have to add a module in your project:
root
|--app
|----build.gradle
|--library
|--build.gradle
|--settings.gradle
In settings.gradle just add:
include include ':library', 'app'
and in your app/build.gradle add
dependencies{
compile project(':library')
}
One option would be to include the source files directly in your project, by copying to your app/src/main/ directory. If you want to add an extra layer of separation, you could create a new module before copying the files in.
I am building a project with Gradle, but, to maintain consistency with my coworkers' use of the Ant build system, I need to keep the old file structure. How do I refactor my project/file structure to the traditional one?
I thought this would be a common question, but I could not find any answers. Can Android Studio help me here?
How do I refactor my project/file structure to the traditional one?
Start with the traditional one in the first place. Don't change the files -- change build.gradle.
All of my CWAC libraries are published this way, using the legacy project directory structure, but with a build.gradle file (based on the one you can export from Eclipse) that teaches Gradle for Android where everything is.
For example, here is the relevant piece of the build.gradle file for my WakefulIntentService:
android {
compileSdkVersion 17
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']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Here, we are configuring the main sourceset, from a Gradle perspective, telling it where all the different types of "source" come from. Most things, like the Java code, come from the src/ directory in the project, for example.
Some of this is unused in my projects (e.g., pointing the debug and release build types to look for their custom sourcesets off of a build-types/ directory), but I left it there from what Eclipse exported.
I'm migrating to using Gradle in Eclipse. My project links a source directory that I reuse in several other projects.
Now I want to be able to use a Gradle task to build or install my app, but I don't know how to specify the other source directory.
Right now, my Eclipse workspace looks like this:
workspace/
ParentGradleProject/
core/
src/
android/
src/
mySharedLibrary_src/
I tried this but it's still not seeing the external src directory. See second line under main:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', '../../mySharedLibrary_src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
...
}
You can't use Gradle as a build system for Android in Eclipse. The Android Gradle plugin is only supported in Android Studio/IntelliJ CE. This is because the plugin doesn't use normal Java sourceSets; it uses custom sourceSets that Eclipse's Gradle plugin isn't set up to understand. The failure you're seeing is from Eclipse not reading your sourceSet directive, falling back on its default, and only finding src.
The problem i am having is as follows: The root project of my android studio project should in fact be a module. I imported it ages ago from eclipse and it must not have created the common project -> module directory structure needed for gradle.
This is only now becoming an issue as i have to turn the main code-base into a library project and library projects with gradle can only be created within application modules and not the root project.
so basically my project:
should be looking more like this example that ive made:
I have tried adding the wrapping project folder, settings. gradle etc.. in windows explorer and building gradle but to no avail. Is there a way to add a new root to a project in android studio and turn the root into a module without breaking everything??
Note: Making a new project with the correct structure is not an option i dont think because my project is already a remote git repository on other production apps.. Any help would be greatly appreciated.
P.S: If gradle was my girlfriend, i would have broken up with her by now!!
Figured it out eventually. Adding the wrapping project folder, settings. gradle etc was the right thing to do. Turned out that my app build.gradle folder had the following redundant source set
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
This was preventing gradle from indexing my new main java directory folder and the new location of my app manifest.
This question already has answers here:
Using gradle project in both Eclipse and IDEA
(2 answers)
Closed 8 years ago.
Android Studio is still in preview, however many projects are already using Gradle build system which is integrated into Android Studio.
Being an early access preview however, migrating a whole project to Android Studio is too risky, and migration seems to be a one way process.
Is there a way for a single Android project to work seamlessly in both environments (IDEs: Eclipse, Android Studio; and build systems: Ant, Gradle)?
You could set your build.gradle in android studio like this:
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
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')
}
}
But I suggest to use Android Studio. I use it from 0.3.6 and I find it easier to use than Eclipse.
I've made Apps with native lib, modules and the only problem I've found was that strings.xml was reformatted after create a new Activity.