What happens when android studio syncs a project? - android-studio

When we open a project in the android studio, it automatically starts syncing. What does happen during this process?

The Build window already tell you what they are doing.
First, apply ijinit.gradle, this seems a Initialization Script.
Then apply settings.gradle, it indicates modules needs to include for building.
After knowing what modules should be included, it will load and configure the whole project with project level build.gradle, which is a configuration for all the modules inside this project.
Then it will traverse all modules and apply module level build.gradle for each module, and cross configure them (for module dependencies, I think.)

Related

Opened project in android studio and all packages/symbols are marked as incorrect

I am trying to contribute to my first open source project but after forking and cloning from the repo, all files are marked as an error.
Sample error
This is after selecting a source folder.
Current project source
Under package it says: package name does not correspond to filepath
... but I have this
misnamed packages?
Android studio isn't picking up those libraries.
IME there are 2 ways of importing these (I have only had success with the first):
1) copy the source parallel to your own (ie example.com)
2a) include the jar in a libs folder and tell AS to look out for it. (right click will typically provide a good option that I can't recall)
2b) because Android can struggle (ie I couldn't do it, though inroads may have been made since) with importing jars, you may need to use AAR's (android library packages, Android Archive Library (aar) vs standard jar)
However, because this is an open source project, this should all be handled auto-magically for you via the gradle scripts included in the distro.

How to link ndk module using Android Studio

I have an Android Studio project to which I've added an ndk module. My ndk module builds and creates lots of different .so files in various build/intermediates directories. However, when I run the app it is unable to load the library .so from my System.loadLibrary call.
Java files that I include in the same module are found just fine so I was expecting Android Studio to 'find' the ndk files as well.
In looking at the google hello-libs demo I see that they have added a step in the CMakeLists.txt file to set the LIBRARY_OUTPUT_DIRECTORY:
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../distribution)
set_target_properties(gperf
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
"${distribution_DIR}/gperf/lib/${ANDROID_ABI}")
and then added an associated reference in app:build.gradle
jniLibs.srcDirs = ['../distribution/gperf/lib']
Adding similar entries to my project allowed it to run properly.
Is there a simpler way to cause an ndk compiled module to be included in the main application? If not, is there a way to do it without having to figure out all the relative ../../ path elements. I guess I was hoping the module CMakeLists.txt would be
the same configuration regardless of what other projects it might be included in but having to know where it's including project is located seems to break this.

Prevent a project from building if a dependent project fails

I have a VS2010 solution that includes a custom project. The project builds an installer out of all the libraries and executables built in the same solution. This is a third-party installer builder, not a native Visual Studio installer project. It runs a custom command in the post-build event of the project.
The problem with this setup is that the installer project build runs (and succeeds!) even if some other project build fails.
I have added project dependencies so that the installer project depends on all other projects, to no avail. I have also tried to add project references with the same result.
This happens only with this specific project (probably because it's a custom project with configuration type "utility"). Other projects don't start building if a dependent project fails to build.
This is a dangerous situation. A developer may not pay attention to a build failure in some other project and use the incorrectly built installer. I need MSVC to skip building the installer project if some other project fails.
How should I deal with it?
Ideally this should be solved at the MSVC level. I don't want to add custom checks to the installer build command because this would mean I have to maintain a list of projects/targets in two separate places. I also don't want to introduce additional tools to the picture.

Android Studio - How to open multiple project in single window?

I have downloaded Android Studio and started using it for my Android development.
I need to know, how to open multiple number of projects in a single window like Eclipse. Expecting some help, thanks.
IntelliJ IDEA creates a project for the entire code base you work with, and a module for each of its individual components. So, IntelliJ IDEA module is more like an Eclipse project, and project is roughly similar to Eclipse workspace. There's no exact equivalent to Eclipse's workspace that contains all your work, but you can open multiple projects in multiple frames at the same time.
This table can help you see how Eclipse and IntelliJ IDEA concepts map to each other:
Eclipse IDEA
Workspace Project
Project Module
Project-specific JRE Module JDK
User library Global library
Classpath variable Path variable
Project dependency Module dependency
Library Module library
To use the library add it as a dependancy:
File > Project Structure > Modules > Dependencies
Then add the module (android library) as a module dependency.
Open two projects in a single window is not possible in Android Studio / IntelliJ IDEA. So, when you open a second project, you'll have to decide:
New projects can either be opened in a new window or replace the project in the existing window.
How would you like to open the project?
This limitation is useful because your window offers project specific features, like the Changes tab for VCS information, etc.
How to use library projects?
For now, you can copy the library project into your project folder and declare it as a module dependency. If you use the same libraries in different projects, you will end up having the code multiple times.
ProjectA ProjectB
facebook-sdk/ actionbarsherlock/
actionbarsherlock/ bin/
bin/ src/
src/ ...
AndroidManifest.xml
While this feels kind of inconvenient, it helps having all the required sources in VCS. Soon, Gradle, the new build system, will manage these dependencies pleasantly. Here's an example of how the Gradle build could look like to include ActionBarSherlock or similar libs:
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:library:4.2.0'
}
In this answer you'll find some reasons why this solution does not work yet.
write code in settings.gradle
include ':ProjectName'
project(':ProjectName').projectDir = new File(rootDir, '/ProjectName')

How can i tell visual studio to rebuild project when dependant library has been rebuilt

In my solution i have two projects.
One is a library that generates a .lib file on build.
The other is a test application using the library.
I have set the test project to be "dependent" on the library project.
However when i make changes to the library and press F5 to run the sample, it does not rebuild the sample. The dependency option only seem to make sure that the library is built when running the sample.
"On run,when projects are out of date" is set to "always build".
I'm using vs12.
you have set the Test project dependant on the Library but for this scenario you want that reversed.
Visual studio will not allow you to have a circular reference, so you will have to remove the project dependency for Test to Library and re-add it as Library to Test while you are working in this way.
The most common scenario would be a client app(Test) that is dependant on the Library and any changes on the Library would require a manual rebuild of the client, due to the fact the Library change may have broken signatures, types etc.

Resources