Android Studio : difference between src/androidTest and src/main folders? - android

I am new to Android Studio.
My questions are :
what is the difference between src/androidTest and src/main folders ?
where should put all my classes ?

Refer Android Studio Overview
Each instance of Android Studio contains a project with one or more application modules. Each application module folder contains the complete source sets for that module, including src/main/ and src/androidTest/directories. For the most part, you will need to modify the files under each module's src/main/ directory for source code updates, the gradle.build file for build specification and the files under src/androidTest/ directory for test case creation.

In Android Studio 1.0 the scheme has changed a little bit.
Your path should be (app)/src/androidTest/java/com/myapp/HelloWorldTest.java
Here's how I set up Unit Tests in a new Android Studio project:
Open app in Android Studio.
Set the Project explorer (left hand window) to display 'Project' mode.
Tap the little drop-down at the top left and select 'Project'.
Right click the 'src' directory, 'New -> Directory'.
Call new directory androidTest
Right click androidTest and add a 'java' directory.
It will appear in green (indicating it's a test src directory).
Now right-click again and add a package, e.g. com.mycompany.myapp.tests
Add a new class that extends AndroidTestCase.
http://envyandroid.com/content/images/2014/02/project-structure.png
For putting the classes:-
src folder --> main folder --> then java

To be precise on androidTest:
Unit tests run on a local JVM on your development machine. Gradle plugin will compile source code found in src/test/ and execute it using the usual Gradle testing mechanisms.
To answer in a word. The main difference between androidTest and android and main folders is the former is for "Testing" while the later is for Development.

Related

How to add resources folder in core or desktop application in libgdx?

I am making an desktop 2D game in android studio.I need to add resources files in resource folder.Shall i have to make a folder after src folder and add those files there or should i add resources to assets folder in android and link it up.If yes how do I link it up?
Game With Android module : Put your resources inside assets folder of android module , develop and deploy your desktop game.
Run using Run/Debug Congiuration
Working directory : <project path with name>\android\assets
Run or deploy using Gradle task, check below statement inside gradle file of desktop module
project.ext.assetsDir = new File("../android/assets"); (default access)
Game Without Android module : Create assets folder inside core module, put all your resources inside that folder.
Run using Run/Debug Congiuration
Working directory : <project path with name>\core\assets
Run or deploy using Gradle task, check below statement inside gradle file of desktop module
project.ext.assetsDir = new File("../core/assets");
Open Terminal and run your desktop project using gradle task
gradlew desktop:run on Windows or ./gradlew desktop:run on MacOS
If you like to access the resources from both the desktop and the Android app, put the resources in core/assets and add the following line to the :core config:
project(":core") {
sourceSets.main.resources.srcDirs = [ "../core/assets" ]
// ...
}
Accessing a font located at core/assets/font/someFont.ttf would look like this then:
Gdx.files.internal("font/robotoblack.ttf")

Android Studio Project with multiple gradle files (one for each flavor)

I am working on a project that has structure like
Project
|+.gradle
|+.idea
|+.navigation
|-app
|+build
|+keystore
|+libs
|-src
|+androidTest
|+Samsung
|+Motorola
|+HTC
|-app.iml
|-build.gradle
|-build-Samsung.gradle
|-build-Motorola.gradle
|- ** How to add build-HTC.gradle file here? **
...
...
As you can see, there is specific code in Samsung and Motorola directories (not expaned above) and there are specific gradle files (build-Samsung.gradle and build-Motorola.gradle) in addition to build.gradle file.
I have to follow this structure and have to add another vendor specific flavor for say HTC. How do I create "build-HTC.gradle" file in directory structure above in Android Studio.
Sorry, this might be very basic question but I was not able to find anything online and if I right-click on my src directory and chose New, I dont see option for gradle file.
Thanks

Android - How do I create the assets folder manually?

I'm new to Android development, and I'm trying to manage projects from the command line using the SDK since I cannot get Android Studio 1.2 to work properly in my system (it's unresponsive).
The problem: I created a new project but the asset folder is missing.
Other SO answers (enter link description here) solve this by creating the folder from the IDE, or by pointing to the asset folder in the .iml file, with doesn't work in my case (I trying to mange the projects from the command line entirely)
There's also a solution editing build.gradle, but the project created from command line (using the SDK) doesn't seem to be a gradle project.
Any help would be appreciated.
Just create a directory called "assets" at the root of your project, i.e. in the same directory your AndroidManifest.xml lives. There's no need to "link that folder from the project". At least that's the case on my system, where I'm using Android SDK 24.4.1 (and I'm not using Gradle -- just emacs and ant).
Once I had assets/fonts/aisauc.ttf in there, the following code...
import android.graphics.Typeface;
...
Typeface greek =
Typeface.createFromAsset(getAssets(), "fonts/aisauc.ttf");
mytextfield.setTypeface(greek);
gave me a TextField with characters from the font I wanted.
How do I create the assets folder manually?
You make it the same you make any directory on your filesystem. Whether you use mkdir or a command-line equivalent, or whether you use your desktop OS's file manager, is up to you.
The default location for an assets/ directory is in a sourceset (e.g., src/main/assets/, to go along with src/main/AndroidManifest.xml and src/main/res/ and src/main/java/, where src/main/ is a sourceset). You can have an assets/ directory located elsewhere, if you choose, but then you will need to configure your build.gradle file to teach Gradle the alternative assets/ location for whatever sourceset you are trying to apply it to.
In your left most sidebar or the sidebar that shows the app, manifests, java... etc, right click app > New > Folder (has the green android symbol next to it) > Assets Folder.
On the next screen leave the path as 'main' and click 'Finish'. Then you can drop whatever asset you want into the folder.

Android Studio 1.2 migration?

I am following some posts/questions about AndroidStudio-1.2 and it seems that there is a different project structure: app/src/main; while my old 1.0 project looked like: src/main (no app).
Not sure if this is causing this, but I am not able to get gradle to identify any test files, while running tests.
You probably have to rename src/test to src/androidTest.
The app directory is a subproject directory. By default AndroidStudio generate a structure ready for multi-module project. i.e. :
a root directory with the root build.gradle + gradle.settings (listing all modules in your project)
a subdirectory (named "app") where you can put all the sources for your application.
Later it is more easy to add a library module (just create a directory myLib in the root folder).
This structure is just proposed by AndroidStudio: you can also use AndroidStudio with only one level of directory and one single build.gradle.

Creating a new Android Project in Terminal-IDE

Is there a script or something that creates a new Android project in Terminal IDE on Android? How does the R file get updated with new resources?
This might help : http://developer.android.com/tools/projects/projects-cmdline.html
It will create a project that can be used...with ant.
Maven has an archetype system that can create a new Android project : https://github.com/akquinet/android-archetypes
There doesn't seem to be any gradle equivalent (yet).
You need to create your project's home folder and then create the
./src
./dist
./res
./build
./build/classes
directories and add an "AndroidManifest.xml" file manually.
It works. Copy the "builder.sh" script in the project's home folder and make the proper changes like cd into your project's home folder, set your project's package name and select the main activity class.
As per your question about the R.java file, the aapt tool from Android SDK detects the changes in resources and writes R.java file and packs resources accordingly.

Categories

Resources