I set up my libgdx projects with HTML5 and Desktop, but later decided to add Android support. How do I add the Android project?
I'm afraid if I use the setup UI again it'll overwrite my code..
Use the setup-ui once more with exactly the same parameters like you did when you were initially creating the projects, but use another destination folder. Then re-create all of them again.
When you are done with that, copy the android folder to your original projects. You will also need to copy some of the single files in the root folder. Those are settings.gradle and build.gradle. If you have changed your build.gradle file manually already, you should only copy the part for the android project to the original file instead of replacing it.
After that you should re-import all the projects into your IDE once more.
Related
The question
When you need to use resource files, such as images, in your Android project, typically you put them in the res directory (e.g. res/drawable), and the Android build process picks them up by default. But what if your resource files come from a directory outside of your Android project? How do you copy them into a folder like res/drawable during sync or build?
What I have tried
I have a feeling that the solution is to write Gradle code, but I'm not sure how to do it. I tried the following code in my app module build.gradle file:
task copyResources(type: Copy) {
from '../../../images'
into 'res/drawable'
}
But it did not copy anything as far as I can tell. This is probably just my ignorance of how to use Gradle, and I could use some help.
I realize I could manually copy from ../../../images to res/drawable, but let's say those files change often, and I want to get the current version automatically whenever I sync or maybe whenever I build. If this is possible, I would appreciate knowing how to do it. If it is not possible, I would like to know that as well.
See How to run copy task with android studio into assets folder
Can do with adding
preBuild.dependsOn copyResources
after task copyResources(){...}
in your build.gradle.
But, it's not a good way for copying resources.
Generally you don't want to do that. The reason is that it makes what would otherwise be a clean source control system confused by the copied files.
A better idea would be to build an Android library (AAR) housed in a separate project, then consume them by adding that AAR as a dependency to the parent project.
I want to use layouts,values,dimens., etc of my previous project/app in my new project. Basically, I want to import the whole res folder of my previous project into the new one. I know I can copy-paste the stuff I need, but in this case I need the whole folder as it is. So, is there an easy way to do it? I'm using Android Studio.
You could extract your resources to a libraryproject. Other projects can use this libraryproject as a dependency and can make use of the resources. Changes in the libproject will also affect other projects. So you don't have to copy&paste new code.
If you want to use another project's res folder, you just need to copy and paste it under app folder of android studio project.
You can't address the other Project Directory to your current project.
For Android Development all your resources need to be in your current project's directory within respective folder in "/res/" folder.
I develop an SDK, and would like to be able to check in module files for both IntelliJ IDEA and Android Studio. I've devised the following solution, with one missing piece:
Create module files ending in -intellij-idea for the main project, and each module.
Create build.gradle files, and use the "sourceset" directive to use the old style src and res directory structure.
The problem is that the project information is always stored in a directory called ".idea". Before, I could have two IPR files, such as my-project-android-studio.ipr and my-project-intellij-idea.ipr. I could then open one in Android Studio, and the other in Intellij IDEA, but the actual source would remain the same.
How can I accomplish this? If there is a way to force Android Studio to generate IPR files instead of the ridiculous .idea directory, that would be optimal.
In my project I have added some folders that I want included in my project for source files. But no matter what I do, the source never gets recognized. I tried refreshing, clean up, restarting but nothing works. Here is the project's source folder:
I want the folders integration/android added. This is how it is showing up in Eclipse:
And here is what my build configuration looks like:
I could be wrong, but it looks like you have added them as a folder, but not actually added the folder to your project.
The folder should show up in your src folder in the solution explorer window under your other package.
Try creating the package name in your project, then move all the src files into it.
And when its in the src folder, in its correct package, you dont need to include any extra build paths.
(You can have multiple packages in a single application)
Importing someone elses project that is over 2 years old is almost always problematic. I found the easiest solution just to create a fresh project and add the files manually from the old project.
I'm using a default Eclipse project file generated for my Android application, and I want to keep it in a targets/ directory (along with other eclipse-specific files) in order to better organize my project structure (I also plan on adding a target for NetBeans).
Simple question, I suppose: Is this possible?
Coming back to this question, Ryan Conrad is correct in that Eclipse needs the .project files in the root of the project directory. As such it is not possible to move it elsewhere.
You can define target or output destination by change the output folder. I guess you can do that by change the dir path under Property of the Android project.
If you want to reorganize all your Eclipse projects, you can create a new workplace (Files/Switch workplace) and start creating new projects from now on.