Android Studio project with old eclipse project structure disadvanteages? - android

In this thread both project structures were already compared. The question that is still open for me is if there is something that won't work or any disadvantages or staying with the old eclipse project structure after migrating to Android Studio? We have migrated a really big project to Android Studio staying with the old structure and all works fine, changing the structure of such a big project would be really complicated, are there any advantages with doing so?

You can stay with old Eclipse project structure. All you has to do is set up correct path to your code in build.gradle config file:
android {
...
sourceSets {
main {
manifes.srcFile 'path/to/AndroidManifest.xml'
java.srcDirs = ['path/to/src']
resources.srcDirs = ...
aidl.srcDirs = ...
res.srcDirs = ...
assets.srcDirs = ...
jni.srcDirs = ...
}
androidTest {
java.srcDirs = ['path/to/android/tests']
res.srcDirs = ...
...
}
test {
java.srcDirs = ['path/to/unit/tests']
}
}
}
Only thing that may be confusing that if you are using proxy and configure it in AndroidStudio, it will inject parameters as plain text in your root gradle.properties file. If you are using gradle.properties, i.e. you are inject variables from Jenkins, it can be frustrating, and also you can suddenly commit this file with all your credentials. To avoid it, you can use project structure with modules:
/root
-build.gradle
-gradle.properties
-module/
-module/build.gradle
-module/gradle.properties
In this case, you can hold your gradle variables in module/gradle.properties, and root gradle.properties will be used for AndroidStudio purposes.

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.

Android Studio Gradle androidTest vs instrumentTest

I'm adding unit tests to my existing Android Studio project and I'm a bit confused with the setup. Particularly, the androidTest vs instrumentTest flags within the gradle script. Can someone explain the different between these 2 sections and what exactly they target vs the other.
My project was migrated from an Eclipse project, so it does not have the default gradle structure. Here's what I've been playing around with:
androidTest {
setRoot('tests')
java.srcDirs = ['tests/src']
}
instrumentTest {
setRoot('tests')
java.srcDirs = ['tests/src']
manifest.srcFile file('tests/AndroidManifest.xml')
}
Is there any reason to have both?
Is there any reason to have both?
No, because they are the same thing, as instrumentTest was renamed androidTest in version 0.9.0 of the Gradle for Android plugin.

properties file not found after migrating Android project from eclipse to Android Studio

My Android project contains some property files in the package structure. To read this property I use MyClass.getResourceAsStream("someProperties.xml"). MyClass has no access to a Context.
After migrating to Android Studio the someProperties.xml is not moved into the resulting package structure. Therefore my code can't find the file.
What can I do to read my file again? How can I modify the gradle build to have the file copied to my package structure again or is the a possibility to read resources without a context and put the file into assets?
I guess you have not specified within gradle where those resources are located.
Defaults are different in Eclipse ADT and Android Studio.
Here are defaults for Eclipse (when java sources already in src/main/java)
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
see MAKE ANDROID ECLIPSE PROJECT READY FOR ANDROID STUDIO, YET KEEPING IT ACCESSIBLE FOR ECLIPSE USE TOO

Migrate Eclipse project to Gradle

I'm trying to move my current android project to a Gradle project, so here what I've done so far:
add gradle to eclipse
generation of build.gradle file
create ANDROID_HOME environment variable in Windows 7
at the root of my project in command prompt: gradlew build
So now, I've got a new folders structure in my project:
It's my first time with gradle, I guess I missed something and I would like to know if to finish this migration I have to delete the src and res directories (in blue) ? For me I just have to get a new structure of folders after the generation of gradleview build..
And if what I've generated looks like to a gradle project ?
If your project structure does not fit to android studios structure you can add your folders to the source set in the gradle file of your app.
So your android studio will match the correct folders
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Project-Structure
sourceSets {
main {
// manifest.srcFile 'src/main/AndroidManifest.xml'
// java.srcDirs = ['src/main/java', 'build/generated/source/apt/${variant.dirName}']
// resources.srcDirs = ['src/main/resources']
// res.srcDirs = ['src/main/res']
// assets.srcDirs = ['src/main/assets']
}
}
as copied from here
There was typo: use gradlew build or gradle build
You can keep Eclipse folder structure and configure it in build.gradle
Yet I would recommend to move source into src/main/java.
Eclipse would be quite OK with that.
http://www.nodeclipse.org/projects/gradle/android/Make-Android-Eclipse-project-ready-for-Android-Studio

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.

Categories

Resources