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.
Related
I'm trying to move my IntelliJ IDEA (2017.3) Android project to another computer just copying the files and it does not work. I am aware of this and this, but in the case of Android project it does not work. All the xml files inside .idea store paths relative to the home ($USER_HOME$) instead of project home ($PROJECT_DIR$). Oddly, Maven projects seem to generate paths relative to the project home and those ones can be copied. But not with gradle projects.
Anyone knows how to solve this ?
EDIT: Bear in mind that I want to copy ALL project settings included running configurations. I want that someone opens the project and find exactly what I have. I know I can reimport the project, but then I'll loose some configuration.
Here's the files and folders that need to be excluded from the copy (assuming that your project has a module called app), preferably if you copy the entire project folder to some where else on the same computer and then deleting the unneeded one by one:
folders .idea, .gradle or any folder who's name starts with a .. They are usually found within the root folder of the project and within the module root folder.
build folder found in the project root folder and in module root folder.
any file who's extension is .iml, found in the project root folder and in module root folder.
local.properties found in project root folder.
The rest of the files and folders need to be kept. With the above excluded, the project can be re-imported in Android Studio properly with the correct configurations relative to your second PC.
On a side note, these are the typical exclusions added in .gitignore of an Android Project Git Repo.
Ok, I found the problem. It is related to how gradle resolve symlinks. This is the issue. Summarizing, if you open your project with a path that contains a symlink, absolute paths will be created in the configuration files and your project won't be portable.
I have reopened the project again using an absolute path and then all the configuration files use PROJECT_DIR instead of USER_HOME
I am writing an Android app using IntelliJ IDEA.
My project file is generated as android.iml because my project folder is named android.
The project folder of my partner is named cleverlotto (app name). Because of this IntelliJ generates a second project file named cleverlotto.iml.
Now we are working with different project settings.
So how can we use the same project file without using the same project folder name?
I asked the same question to Jetbrains Support.
Answer:
It is not possible to rename root module without also renaming root
directory of the project.
I'm ussing the usual way to link android studio modules to a project:
include ':app'
include ':coretools'
project(':coretools').projectDir = new File(settingsDir, '../base/CoreTools/app')
This works as expected but the problem is that this generates a coretools.iml file in the used module folder. I mean, in the above example a coretools.iml is generated under base/CoreTools/app.
The main concern is that this coretools.iml generated file has references to the project that used this module and it is a nightmare to use the module in different projects by different users with a CVS like git.
The question is: Is there any way to avoid this .iml creation? Is this "as designed" and can't be avoided?
Thanks
Please refer to the module documentation:
A module is a discrete unit of functionality which you can compile,
run, test and debug independently.
Modules contain everything that is required for their specific tasks:
source code, build scripts, unit tests, deployment descriptors, and
documentation. However, modules exist and are functional only in the
context of a project.
Configuration information for a module is stored in a .iml module
file. By default, such a file is located in the module's content root
folder.
Development teams, normally, share the .iml module files through
version control.
As you can see there is a lot of useful project-related information in the .iml files but the documentation doesn't state that you always must share those files though a CVS. If the .iml files are a pain for your development team just add them to your .gitignore file.
I finally ended just ignoring all *.iml in the library module but the one belonging go the module. Something like this in the .ignore file did it:
*.iml
!app.iml
being the app.iml the real/original module iml file.
Cheers.
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.
I have setup an android test project for my application in ECLIPSE. My test project depends on some external libraries for Mock behavior.
I can add dependencies to my test project in following ways:
If I put all the dependency jar files to my 'application\libs' folder, but they will be bundled with my application APK, irrespective of that my source does not depend on the these jars.
If I put all the dependency jar files to my 'testProject\libs' folder, run test from ECLIPSE and success but logcat keeps givieng me warning of not finding classes. and i have read on SO that ant ingnores 'test\libs'? so is that the same case with ADT also.
So is it good practice to put external dependencies of test project in 'test\libs' only?
NOTE: In both the cases my test get run successfully But I am curious to get the right way.
If you are adding external dependencies in android libs folder is most recommended. Just follow this following steps:
1.Create a folder called libs in your project's root folder.
2.Copy your JAR files to the libs folder.
3.Now right click on the Jar file and then select Build Path > Add to Build Path, which will create a folder called 'Referenced Libraries' within your project.
Third step gives reference to your libraries file.