Android studio project files missing from source control - android

I am looking a source code repository and it only contains code for an Android project i.e. src/main/java/com/.. and no project definition files such as .idea, .iml ,.ipr, .iws - These files are included in the .gitignore file.
There are no files relating to an Android Studio project at all so I cannot open in the IDE. It has been set up for Maven so I can build that way. If I want to run/debug/alter this project what do I do?
Why would somebody exclude all IDE project files?

It's easy, the repository/source code owner don't commit the project files because the source code must be independent of the IDE used by people. The projects files of Eclipse are different from one of IntelliJ.
You can clone or download the source code and even not use any IDE. Some poeple prefer working with editors like Emacs or Vi and build the project using the command line.

There are many ways to create android projects with Android Studio and Eclipse being the main two.
If the author had to maintain project files it would add considerably to the work required as IDEs etc get updates at different rates.
This way the code is "portable" between IDEs and the author can focus on just supporting his work rather than all of the combinations of IDE/Operating Systems.

My Solution
I am posting solution here as I cannot yet answer my own question.
So, I the solution was in the Maven definition. My codebase was an SDK consisting of numerous libraries and sample apps. Each component had a POM.xml and was all contained using a Parent POM.
All I did was import the Parent POM into Android Studio. Once triggered Android Studio would create its own project files using the POM definitions for each component. All the modules were available in one instance and it built and ran instantly. It was truly beautiful :)
Steps: Import Project -> Select directory containing POM.xml -> "Import project from external model" -> Maven -> Next -> continue to create project.

Related

Importing eclipse android project into android studio

I am trying to import an android project created in eclipse into android studio. This main project also refers to another library project in the same eclipse workspace. The folder structure is like this:
workspace\app1
workspace\lib1
When I import the main project into android studio, the library project is automatically imported as a sub-project (or shall we call it a module) within the main project. That's not what I want. The library project is shared by multiple apps I am maintaining. It should sit in parallel with other app projects in terms of folder structure. I wouldn't want it to go understand any particular app project.
Please help explain how I can make the library project stand its own and refer to the library project from other app projects in android project. I am fairly new to the gradle build system. So detailed instructions would be highly appreciated. Thanks a lot!
Since you are importing in android studio, I assume you are moving to gradle build system. In your case , I think, it would be best to have a separate AS project for library. Use that project to generate a jar file and then import that jar using gradle build script in each project you want to use it.
If you are sharing the same library across multiple, you can configure them as separate AS project and have "aar" file as output. (In your gradle you put>> apply plugin: 'android-library'). You then define them as dependency in your gradle file. (either through maven repo or putting it in your libs directory and defining it in your dependencies section). You can find more info at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-projects
You can use version control tool such as git to synchronize the library project in every main project. But you need to use a version control tool to manage all your projects first.
Read here on "AS Modules"
review 57.1.2 on "common behavior"
Take a look at a project built on AS pattern of modules as libs used in eclipse (gradle.settings) pictured
all the includes are modules
maybe you can rethink the idea of how to get AS to work for you in reusing code....

How do you import an Eclipse project into Android Studio now?

Using "Import Project" in Android Studio for an Eclipse project used to change the project structure and generate Gradle files, but right now (I'm using AS 0.5.3) it's only generating IDEA files (.iml, .idea) but not Gradle and it's not touching the file structure either.
How do you import an Eclipse project into Android Studio now?
Update: Trying to export gradle files in Eclipse won't export them for the app, it doesn't show up as a module in Android Studio either.
In newer versions of Android Studio, the best way to bring in an Eclipse/ADT (Android Development Tool) project is to import it directly into Android Studio; we used to recommend you export it from Eclipse to Gradle first, but we haven't been updating ADT often enough to keep pace with Android Studio.
In any event, if you choose "Import Project" from the File menu or from the Welcome screen when you launch Android Studio, it should take you through a specialized wizard that will prompt you that it intends to copy the files into a new directory structure instead of importing them in-place, and it will offer to fix up some common things like converting dependencies into Maven-style includes and such.
It doesn't seem like you're getting this specialized flow. I think it may not be recognizing your imported project as an ADT project, and it's defaulting to the old built-into-IntelliJ behavior which doesn't know about Gradle. To get the specialized import working, the following must be true:
The root directory of the project you import must have an AndroidManifest.xml file.
Either:
The root directory must contain the .project and .classpath files from Eclipse
or
The root directory must contain res and src directories.
If your project is complex, perhaps you're not pointing it as the root directory it wants to see for the import to succeed.
Export from Eclipse
Update your Eclipse ADT Plugin to 22.0 or higher, then go to File | Export
Go to Android now then click on Generate Gradle build files, then it would generate gradle file for you.
Select your project you want to export
Click on finish now
Import into Android Studio
In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window.
Click Import Project.
Locate the project you exported from Eclipse, expand it, select it and click OK.
Try these steps:
1- click on Import project (Eclipse, ADT, ...)
2- Choose main directory of your Eclipse project
3- Keep the defaults. The first two options is for changing jar files into remote libraries (dependencies). It mean while building Android studio try to find library in local system or remote repositories. The last option is for showing only one folder as app after importing.
4- Then, you will see the summary of changes
5- Then, if you see Gradle project sync failed, you should go to project view (top left corner). Then, you should go to your project-> app and open build.gradle.
6- Then, you should change your compilesdkVersion and targetsdkVersion to your current version that you see in buildToolsVersion (mine is 23). For example, in my project I should change 17 to 23 in two places
7- If you see an error in your dependencies, you should change the version of it. For example, in my project I need to check which version of android support library I am using. So, I open the SDK manager and go to bottom to see the version. Then, I should replace my Android studio version with my current version and click try again from top right corner
I hope it helps.
Its Got simpler with Android Studio
All you need is to first choose
import project(eclipse.....)
then choose your folder eclipse based project.like this one below
3.based on the type of project and library you used like (ActionBarSherlock) you may prompted special import wizard so go ahead and click next then finish.
in this case it was simple one
4.And you are done.
but sometimes the debug or Run options do not work and a error msg shows like
"this project structure is not gradle based or migrate it to gradle"
something
to solve this
close the opened eclipse project and reopen same project through the same process as we did before with import project (eclipse adt,gradle,etc)) this time android studio gonna add all necessary gradle files and green debug option will work too.
i have did this somehow accidentally but it worked, i just hope it works for you too.
Android Studio has been improved since this question was posted, and the latest versions of Android Studio (as of this writing, we are at 2.1.1) have fairly good Eclipse importing capabilities, so importing Eclipse projects directly into Android Studio is now the best approach for migrating projects from Eclipse into Android Studio.
I will describe how to do this below, including a few of the pitfalls that one might encounter. I will deal in particular with importing an Eclipse workspace that contains multiple apps sharing one or more project libraries (the approaches posted thus far seem limited to importing just one Eclipse app project and its project libraries). While I don't deal with every possible issue, I do go into a lot of detail regarding some of them, which I hope will be helpful to those going through this process for the first time themselves.
I recently imported the projects from an Eclipse workspace. This workspace included four library projects that were shared between up to nine projects each.
Some background:
An Eclipse workspace contains multiple projects, which may be library projects or apps.
An Android Studio project is analogous to an Eclipse workspace, in that it can contain both library projects and apps. However, a library project or an app is represented by a "module" in Android Studio, whereas it is represented by a "project" in Eclipse.
So, to summarize: Eclipse workspaces will end up as Android Studio projects, and Eclipse projects inside a workspace will end up as Android Studio modules inside a project.
You should start the import process by creating an Android Studio project (File / New / New Project). You might give this project the same (or similar) name as you gave your Eclipse workspace. This project will eventually hold all of your modules, one each for each Eclipse project (including project libraries) that you will import.
The import process does not change your original Eclipse files, so long as you place the imported files in a different folder hierarchy, so you should choose a folder for this project that is not in your original Eclipse hierarchy. For example, if your Eclipse projects are all in a folder called Android, you might create a sibling folder called AStudio.
Your Android Studio project can then be created as a sub-folder of this new folder. The New Project wizard will prompt you to enter this top-level project folder, into which it will create your project.
Android Studio's new project wizard will then ask you to configure a single module at the time you create the project. This can be a little confusing at first, because they never actually tell you that you are creating a module, but you are; you are creating a project with a single module in it. Apparently, every project is required to have at least one module, so, since you are relying on Eclipse to provide your modules, your initial module will be a placeholder to vacuously satisfy that formal requirement.
Thus, you probably will want to create an initial module for your project that does as little as possible. Therefore, select Phone and Tablet as the type of your module, accept the default minimum SDK (API level 8), and select Add No Activity for your module.
Next, select one of the Eclipse app projects in your workspace that requires the largest number of libraries as your first project to import. The advantage of doing this is that when you import that project, all the library projects that it uses (directly, or indirectly, if some of your library projects themselves require other library projects) will get imported along with it as part of the importing process.
Each of these imported projects will get its own module within your Android Studio project. All of these modules will be siblings of one another (both in your project hierarchy, and in the folder hierarchy where their files are placed), just as if you had imported the modules separately. However, the dependencies between the modules will be created for you (in your app's build.gradle files) as part of the importing process.
Note that after you finish importing, testing and debugging this "most dependent" Eclipse project and its supporting library projects, you will go on to import a second Eclipse app project (if you have a second one in your workspace) and its library project modules (with those imported earlier getting found by the import wizard as existing modules and re-used for this new module, rather than being duplicated).
So, you should never have to import even a single library project from Eclipse directly; they will all be brought in indirectly, based on their dependencies upon app projects that you import. This is assuming that all of your library projects in the workspace are created to serve the needs of one or more app projects in that same workspace.
To perform the import of this first app project, back in Android Studio, while you are in the project that you just created, select File / New / New Module. You might think that you should be using File / New / Import Module, but no, you should not, because if you do that, Android Studio will create a new project to hold your imported module, and it will import your module to that project. You actually could create your first module that way, but then the second through Nth modules would still require that you use this other method (for importing a module into an existing project), and so I think that just starting with an "empty" project (or rather, one with its own vacuous, do-nothing placeholder module), and then importing each of your Eclipse projects as a new module into that project (i.e., the approach we are taking here), may be less confusing.
So, you are going to take your practically-empty new project, and perform a File / New / New Module in it. The wizard that this invokes will give you a choice of what kind of module you want to create. You must select "Import Eclipse ADT Project." That is what accesses the wizard that knows how to convert an Eclipse project into an Android Studio module (along with the library modules on which it depends) within your current Android Studio project.
When prompted for a source folder, you should enter the folder for your Eclipse project (this is the folder that contains that project's AndroidManifest.xml file).
The import wizard will then display the module name that it intends to create (similar to your original Eclipse project's name, but with a lower-case first letter because that is a convention that distinguishes module names from project names (which start with an upper-case letter). It usually works pretty well to accept this default.
Below the module name is a section titled "Additional required modules." This will list every library required by the module you are importing (or by any of its libraries, etc.). Since this is the first module you are importing, none of these will already be in your project, so each of them will have its Import box checked by default. You should leave these checked because you need these modules. (Note that when you import later Eclipse app projects, if a library that they need has already been imported, those libraries will still appear here, but there will be a note that "Project already contains module with this name," and the Import box will be un-checked by default. In that case, you should leave the box unchecked, so that the importer will hook up your newly-imported module(s) to the libraries that have already been imported. It may be that accepting the default names that Android Studio creates for your modules will be important for allowing the IDE to find and re-use these library modules.
Next, the importer will offer to replace any jars and library sources with Gradle dependencies, and to create camelCase module names for any dependent modules, checking all those options by default. You should generally leave these options checked and continue. Read the warning, though, about possible problems. Remember that you can always delete an imported module or modules (via the Project Structure dialog) and start the import process over again.
The next display that I got (YMMV) claims that the Android Support Repository is not installed in my SDK installation. It provides a button to open the Android SDK Manager for purposes of installing it. However, that button did not work for me. I manually opened the SDK manager as a separate app, and found that the Android Support Repository was already installed. There was an update, however. I installed that, and tapped the Refresh button in the import dialog, but that did nothing. So, I proceeded, and the perceived lack of this Repository did not seem to hurt the importing process (although I did get messages regarding it being missing from time to time later on, while working with the imported code, which I was able to appease by clicking a supplied link that corrected the problem - at least temporarily). Eventually this problem went away when I installed an update to the repository, so you may not experience it at all.
At this point, you will click Finish, and after a bit it should create your modules and build them. If all goes well, you should get a BUILD SUCCESSFUL message in your Gradle Console.
One quirk is that if the build fails, you may not see your imported modules in the Project hierarchy. It seems that you need to get to the first valid build before the new modules will appear there (my experience, anyway). You may still be able to see the new modules in the File / Project Structure dialog (e.g., if you want to delete them and start your import over).
Remember that since you are not changing your original Eclipse projects, you can always delete the modules that you have just imported (if importing goes badly), and start all over again. You can even make changes to the Eclipse side after deleting your Android Studio modules, if that will make importing go better the second time (so long as you preserve your fallback ability to build your existing source under Eclipse). As you'll see when we discuss version control below, it may be necessary for you to retain your ability to build under Eclipse, because the project structure is changed under Android Studio, so if you need to go back to a commit that precedes your move to Android Studio (e.g., to make a bug fix), you will want to have the ability to build that earlier commit in Eclipse.
To delete a module, you must select File / Project Structure, then select the module from the left side of the dialog, and then hit the delete key. For some reason, I was not able to delete a module directly in the Project hierarchy; it had to be done using this Project Structure dialog.
The import wizard generates an import-summary.txt file containing a detailed list of any issues it may have encountered, along with actions taken to resolve them. You should read it carefully, as it may provide clues as to what is happening if you have trouble building or running the imported code. It will also help you to find things that the importer moves around to accommodate the different structure of Android Studio projects.
If all does not go well, then have at look at these possible problems that you may encounter, along with solutions for those problems:
Generally speaking, there are two main kinds of problems that I encountered:
Proguard problems
Manifest problems
When Proguard is messed up, the (obfuscated) names of methods in your libraries may not match the names being used to invoke them from your app, and you will get compiler errors like "error: cannot find symbol class ..."
In Eclipse, Proguard stuff is pretty much ignored for library projects, with the Proguard stuff for any app project that you are building determining the obfuscation, etc. for not just itself, but for processing all of the libraries on which it depends. And that is generally what you want.
In Android Studio, however, you need to make some changes to attain this same effect. Basically, in the build.gradle files for each of your library project modules, you will want something like this:
buildTypes {
release {
minifyEnabled false
consumerProguardFiles 'proguard.cfg'
}
}
Where proguard.cfg is your library module's own proguard configuration file.
The term "consumer" in "consumerProguardFiles" apparently refers to the app module that is using this library module. So the proguard commands from that app are used in preference to those of the library module itself, and apparently this results in obfuscations that are coordinated and compatible, so that all calls from the app module to its library modules are made with matching symbols.
These "consumerProguardFiles" entries are not created automatically during the import process (at least that was my own experience) so you will want to make sure to edit that into your library modules' build.gradle files if they are not created for you during importing.
If you wanted to distribute your library projects separately, with obfuscation, then you would need an individual proguard file for them; I have not done this myself, and so that is beyond the scope of this answer.
In the app module, you will want something like this:
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
(BTW, as of this writing, while my apps are running just fine, I have not yet directly confirmed that things are actually getting obfuscated using this approach, so do check this yourself - e.g., by using a decompiler like apktool. I will be checking this later on, and will edit this answer when I get that info).
The second kind of problem is due to the fact that Eclipse pretty much ignores the manifest files for library projects when compiling an app project that uses those library projects, while in Android Studio, there is an interleaving of the two that apparently does not consistently prioritize the app's manifest over those of its libraries.
I encountered this because I had a library manifest that listed (just for documentation purposes) an abstract Activity class as the main activity. There was a class derived from this abstract class in my app that was declared in the manifest of each app that used the library.
In Eclipse, this never caused any problems, because the library manifests were ignored. But in Android Studio, I ended up with that abstract class as my activity class for the app, which caused a run-time error when the code made an attempt to instantiate that abstract class.
You have two choices in this case:
Use tools syntax to override specific library manifest stuff in your app manifest - for example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.goalstate.WordGames.FullBoard.trialsuite"
xmlns:tools="http://schemas.android.com/tools"
.
.
<application
tools:replace="android:name"
or,
Strip out practically everything from your library modules' manifests, and rely upon the app module's manifest to provide every value. Note that you do need to have a manifest for each library module, but not much more is required than the header and a bare manifest element with just a package attribute in it.
I tried both and ended up with approach 2., above, as the simpler method. However, if you wanted to distribute your library modules separately, you would need to create a more meaningful manifest file that reflects each library module's own individual requirements.
There is probably a more "correct" way to do this which puts requirements (e.g., permissions) for each library in the library manifest itself, and allows the automatic interleaving process to combine these with those declared for the app. However, given that Eclipse ignores the manifests for libraries, it seems safer at least initially to rely entirely on the app manifests and just strip the library manifests down to the bare bones.
Be aware that some of the project properties, and also the manifest attributes, from your Eclipse project will have been used to construct portions of your build.gradle files. Specifically, your compileSdkVersion in build.gradle is set to the project build version from the Eclipse project properties, applicationId is the package name from your app's manifest, and minSdkVersion and targetSdkVersion are also copied from the app's manifest file. The dependencies section of build.gradle comes from the library project dependencies in your project's properties.
Note that this may make some of your AndroidManifest.xml values redundant and quite possibly residual (i.e., unused). This could create confusion. My understanding is that the build.gradle values are the ones that actually have an effect, and that the manifest values like targetSdkVersion are not used any more for purposes of building. However, they may still be used by app stores such as Google Play; I don't know for certain one way or the other, so at this point I am just maintaining them in tandem.
Besides the above two kinds of issue, there are more routine things like importing a project that has a project build level of 22 when you have only installed SDK level 23 in Android Studio. In that situation, it is probably better to edit your app module's build.gradle file to move compileSdkVersion from 22 (the imported value) to 23, than it would be to install the SDK for level 22, but either approach should work.
Throughout this entire process, when something does not build properly and you make a change to try to address it, you might want to try Build / Rebuild Project and/or Tools / Android / Sync Project with Gradle Files, and/or File / Invalidate Caches/Restart, to make sure that your changes have been fully incorporated. I don't know exactly when these are truly necessary, because I don't know how much is done incrementally when you haven't yet had a successful build, but I performed them all fairly regularly as a kind of superstitious ritual, and I'm fairly certain that it helped. For example, when I got a Resources$NotFound runtime error that appeared to be from an inability to find the launch icon resource, I tried all three, and the problem was fixed.
When you have performed the above for your first Eclipse project and have attained a successful build, then with luck, you can select your app module from the dropdown at the top of the Android Studio display to the left of the play button, then click the play button itself, then select a device or Android Virtual Device, and the app should be loaded for running.
Likewise, you should be able to create a signed copy of your app using the Build / Generate Signed APK feature. Note that some import-related errors may appear when running your signed copy that do not appear when using the play button, so you need to confirm that both are working before deciding that your import is complete.
Following this, you will probably want to turn on version control. I am using git myself, but there are a number of other options available.
Version control is mostly beyond the scope of this answer, but there are a few things that are affected by the importing process. First, in Eclipse you might have your various projects in various folders stuck all over the place, but when you import into Android Studio, all modules will be created as direct child folders of your main project folder. So if you had a separate git folder for each project in Eclipse, or for related groups of projects organized under a parent folder for each group (as I did), that is not going to translate very well to Android Studio.
My knowledge of this is limited as I have not worked with version control yet in Android Studio, so maybe there is a way around this, but it appears that all version control in Android Studio is unified at the project level, and so all of your modules will be under a single git archive.
This means that you may need to abandon your old git archive and start fresh with a new archive for your imported source code. And that means that you will want to keep your old git archive around, so that it can be used with Eclipse to perform any needed bug fixes, etc., at least for a while. And you also will want it to preserve a history of your project.
If you are fortunate enough to have had all of your projects organized under a single Eclipse workspace, and if you were using a single git archive for those projects, then it is possible that you might just copy your old git archive from in and under your Eclipse workspace folder to in and under your Android Studio project folder. Then, you could edit any still-relevant .gitignore items from you Eclipse project into the auto-generated .gitignore file for your Android Studio project, and let git figure out what has been changed during the importing process (and some things will have been moved around - for example, the manifest file is no longer at the top level of your module). Others have reported that git is pretty good at figuring out what has changed; I have not tried this myself.
But even if you did this, going back to a commit that precedes your move from Eclipse to Android Studio would be going back to a set of files that would only make sense from inside Eclipse. So it sounds, well, "difficult" to work with. Especially since Eclipse will still be pointing to its original set of project folders.
I personally had multiple git archives for my various sets of related projects, and so I decided to just make a clean break and start git over again in Android Studio. If you had to do this, it could affect your planning, because you would want to be at a very stable point in your code development before making the move in that case, since you will lose some accessibility to that older code within your version control system (e.g., ability to merge with post-import code) once you have made the move to Android Studio.
The part of this answer that pertains to git is partly speculative, since I have not actually worked with version control yet on my imported project files, but I wanted to include it to give some idea of the challenges, and I plan to update my answer after I have worked more with version control inside Android Studio.
According to http://tools.android.com/tech-docs/new-build-system/migrating-from-eclipse-projects,
You have a couple of choices
- simply importing
- pre-exporting first from Eclipse.
Pre-exporting from eclipse may be the better choice if your project contains a lot of relationships that are Eclipse-specific. A.S. cannot 'translate' everything Eclipse can produce. If you want to continue using Eclipse as well as A.S. on this project code, this is the better choice. If you choose this method, please read the above link, there are some important pre-requisites.
Simply importing into AS will let AS 'translate' and rearrange the project, and is the recommended method, especially if you have no intention of returning to Eclipse. In this case, you let the A.S. wizard do everything and you dont need to manually generate gradle files.
In addition to the answer by Scott Barta above, you may still have import problems if there are references to Eclipse workspace library files, with e.g.
/workspace/android-support-v7-appcompat
being a common one.
In this case the import will halt until you provide a reference (and if you've cloned from a git repo, it probably won't be there) and even pointing to your own install (e.g. something like /android-sdk-macosx/extras/android/m2repository/com/android/support/appcompat-v7) won't be recognised and will halt the import, leaving you in no-man's land.
To get around this, look for refs in the project.properties or .classpath files that came in from the Eclipse project and remove/comment them out, e.g.
<classpathentry combineaccessrules="false" kind="src" path="/android-support-v7-appcompat"/>
That will get you past the import stage and you can then add these refs in your build.gradle (Module:app) as indicated in the Android tutorial, like below:
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
}
Here is a simpler way to migrate:
Start off with a sample Android Studio project.
Open android studio and create a new project (or) just download a ‘sample’ studio project here: https://github.com/AppLozic/eclipse-to-android-studio-migration.
Now, open the downloaded project in Android Studio by following the below instructions.
Import eclipse project modules into Android Studio.
Select File -> New -> Import Module
Image title
Next, select the path of the eclipse project and import the modules. In case, if you see the message “Failed to sync Gradle project,” then click on “Install Build Tools and sync project…”
Now, remove the sample project modules by following the below simple steps:
Open settings.gradle and remove “include ‘:app’”
Right click on “app” module and “Delete” it.
Now, what we have is the Eclipse project open in Android studio with the Gradle build.
Here are few other links which might help you:
http://developer.android.com/sdk/installing/migrate.html
Source: http://www.applozic.com/blog/migrating-project-from-eclipse-to-studio/
Simple steps:
1.Go to Android Studio.
2.Close all open projects if any.
3.There will be an option which says import non Android Studio Projects(Eclipse ect).
4.Click on it and choose ur project
Thats't it enjoy!!!
Stop installing android studio 3.0.1 and go back 2.3.3 ( Stable version) . Check for the stable version and you can find them a lot
All you have to do uninstall and go back to the other version. Yes it asks to create gradle file seperately which is completely new to me!
Failure is the stepping stone for success..
The best way to bring in an Eclipse/ADT project is to import it directly into Android Studio. At first GO to Eclipse project & delete the project.properties file.
After that, open the Android studio Tool & import Eclipse project(Eclipse ADT, Gradle etc).

Setting up a project in IDEA with Gradle

I am currently starting on quite a huge Android project which will include up to 5 different Apps. Each of these will be dependent of an android library.
This can easily be done by building the shared android library into .jar file and reference this from each App. But the problem is this project is really on the early stages, therefore the code of the library will change just as often as the Apps. It will be quite a pain to always have the library open in a different project, and build it everytime a change has been made.
First question is how to setup a workspace where you can an App and the library open at the same time, and referencing directly to the library. Without any concern about a .jar file.
If it's not possible any ideas? I can't be the first guy starting quite a large android project with multiple Apps.
In Android Studio do the following:
Create a new project. The project will hold all the different APK projects and the shared library. Use "File -> New Project" or select New Project from the splash screen for AS.
In the project, create a new module for each separate APK. Use "File -> New Module -> Android Application". I'm refering to these types of modules as APK modules.
In the project, create a new module for the shared library. Use "File -> New Module -> Android Library" to create the shared library.
Associate the shared library with each APK module by modifying the "build.gradle" file to add a dependency for the shared library. You must change the "build.gradle" file in each of the APK modules.
dependencies {
compile project(':aaa')
}
Be sure to replace "aaa" with the name of the shared library.
You can have multiple shared libraries if you like.
The code for all the APK modules and the shared library is now accessible under one AndroidStudio project. Another advantage of this approach is that the single project directory that can be turned into a single git repo for the combined APK modules and shared library.
First, IntelliJ doesn't have the same concept of workspace as Eclipse. In a nutshell, the model is as follows: You have one window for each IntelliJ project. An IntelliJ project has one or more IntelliJ modules, which are linked by source. Modules from different projects cannot be linked by source.
Regarding your specific question, I think the easiest solution is to have a single source repo and (multi-project) Gradle build comprising all apps and libraries. This will translate to a single IntelliJ project with one IntelliJ module for each app/library, all linked by source.
If you absolutely need to have separate Gradle builds, and still want a fast turnaround in the IDE, then as far as I know, IntelliJ 13 can add another Gradle build to the same IntelliJ project with the push of a button, and perhaps Android Studio can do the same (not sure). Last but not least, remember that both Android Studio and the Gradle Android plugin are early access previews.
I have tried fiddling with Android Studio and IntelliJ Idea for sometime and the best bet I had was to export everything from eclipse. You could follow the steps below(which is what I usually do.. Does not seem to be a good idea, but it works for sure :) )
Open up ADT or Eclipse and setup a new workspace.
Create the apps and add the library project as a library to those apps. The library project needs to be imported to workspace again(I'm not detailing as I presume you know it)
From File > Export > Android > Generate Gradle Build Files which would generate the gradle build files for the entire workspace. And this then can be opened up in IDEA.
Please do reply if this helps.

Using different revisions of multiple android library projects in multiple client projects (in Eclipse)

First of all I have most of my knowlege about library projects from the google docs and a detailed description of the android build system in this article.
Setup
In my Eclipse workspace I have several client projects that import android libraries. Each client imports a different set of libraries and also some libraries import each other.
Each client has its own subversion repository and all the libraries are in one single subversion repository.
All builds and executes well.
Problems
The client projects and the libraries are not evolving synchronously. Some client projects need older revisions of the libraries. One has to create lots of projects in Eclipse. Some libraries projects have to be created multiple times from different revisions of the library repository.
I need to have lots of libraries because with a single library project all its resources would end up in the client project, even if the client actually does not use any of them. Am I right here?
I check out different revisions of the same library into the workspace. With Eclipse it's not possible to import more than one library projects, because the eclipse projects have the same name in .project file (Eclipse complains about that when trying to import the second one)
Eclipse??
EDIT
The answer of Jarek Potiuk works. But it just solves the Problem described in point 3. I still have to create each library project individually in Eclipse.
Is there a solution where I don't need to create a project in Eclipse for each library project imported? Has someone a working solution with ant?
Let me explain how we deal with it. We are using mercurial subrepo but it should be exactly the same using svn:externals in your case.
0) prerequisite: make sure your .project and .classpath files are commited to repo with your projects....
1) In main project we have a "subrepo" directory and we keep all the external libraries (as subdirectories) there. In mercurial it is done using subrepo, in svn you should be able to link to particular version of the library (SVN tag or branch URL) using svn:externals configuration: http://svnbook.red-bean.com/en/1.0/ch07s03.html
2) Net effect is that when you checkout the main project you automatically checkout the dependent libraries in subrepo directory. So far so good.
3) Now in eclipse you get the main directory failing, because it does not have the library linked..... What you do in this case - "Add new Java Project", type in UNIQUE project name (for example libraryprojectname-mainprojectname. Uncheck "Use default location" and browse to subrepo's library. Eclipse will configure the project for you from existing .project. Add this project as depending project in Android and possibly in eclipse as well... Note! the UNIQUE name will not change the .project name, but it will let eclipse to have more than one of your library projects checked out.....
4) Now when your project compiles commit everything (including .project and .classpath files) to repo...
5) Whenever someone checks out the project, library will be checked out in proper version and the only extra step needed is to repeat point 3) - add new Java Project for subrepo and give the project a unique name... That's about it (Eclipse will internally anyhow refer to subrepo/library directory not to the unique name)

Android Library project out of sync in Eclipse

I have an Android Library project with some Activities and Views, referenced by an Android Application project. The application project has a "linked" folder marked [Android Library] with the sources of my library project.
One thing that seems strange to me, is that the same source file can be opened twice, from the linked folder and from the original library folder. This often results in files being out on sync, and all sorts of nasty things happening.
Any idea of what's going wrong? Thanks in advance!
This is expected behavior. If the same physical folder is added multiple times via resource links, the synchronization state of each of the folders is tracked separately. Here are your options:
Deal with having to manually refresh folders from time to time.
Turn on auto-refresh under Window -> Preferences -> General -> Workspace -> Refresh automatically. I believe this performs ok Windows, but can be very slow on Linux. Actual performance likely depends on the size of your workspace.
Re-structure your projects such that you are not using linked folders to bring in library code. I don't know anything about Android development or ADT, but the standard approach for other Java apps is to add a dependency from app project to library project via Project Properties -> Java Build Path -> Projects.
Check your package name in Manifest file it should be same with your project package name.

Categories

Resources