Android Studio -- Use Gradle with the 'traditional' ordering of files - android

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.

Related

How to implement native Google Play In-app billing in a libGDX project?

I was following this and stuck at "a. Navigate to src/main in the Project tool window."
Because I couldn't find src/main in my project structure (Neither in the explorer)
Like it is shown here:
I think it's because I'm working with a libGDX project.
I tried adding the Module directly under the src (As if I was not working in a android studio environment), but when I build my application, I don't see a generated file named IInAppBillingService.java anywhere.
If you open build.gradle in the android folder of your project, you will see the following block of Gradle code:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
This block configures where Gradle looks for source files. LibGDX uses this to customize the directory hierarchy which is why you are unable to exactly follow the steps given in the Android documentation.
Now the line aidl.srcDirs = ['src'] tells us that the project is configured so that all AIDL files can be placed directly in the src folder. So you can modify the step to navigate to src/main and instead just go directly to src. Follow the rest of the instructions from there. If Android Studio balks at any step, you may have to go directly to the file system using the command line or your favorite file explorer in order to create the folders and files that you need.
It appears you have done this and the second part (or maybe the primary part?) of your question is the location of the generated .java file from your AIDL source. Android Studio places all generated artifacts under the build directory. There is a build folder directly in the base directory of your project and one in each module. Search these for the generated file.

How do I "link source" in an Android Gradle project?

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.

Incorrect project module layout android studio gradle

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.

Android Studio open project structure fail

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

android-studio can't find an aidl interface for use in class

I have an interface defined in the aidl but I can't extend it or find it any way. The ide just tells me: Can not resolve symbol 'KeyEventListener'
Any idea how to fix this?
Additional infos:
KeyEventListener is the name of the interface defined in KeyEventListener.aidl
KeyEventListenerImpl is the class which extends the interface Stub
KeyEventListener just contains one method named 'void doIt();' and is well formatted;
I know android-studio is some thing like a pre-alfa but like it very much and would be very happy if some one could halp me out on this!
In my case Clean and Rebuild project solved my problem.
You are probably best off having a look at The Gradle Plugin User Guide for Android.
Gradle, by default, requires a particular directory structure. If you want to use Gradle with a directory structure that most Android devs are accustomed to, you'll need to put the following (from the above-mentioned link) inside the "android" block.
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
After you've done this, do a clean and rebuild to be on the safe side.
Personally, I just adapt my projects to fit the new convention.
Created a directory aidl under src/main.
Then created the new aidl file package structure and moved aidl file into it.
Rebuilt and it was done.
I followed this post

Categories

Resources