Files under the build folder are generated and shouldn't be edited - android

I want to know if there is any way to edit the BuildConfig.java file in Android Studio, as there is an error when I try to change a variable in that file. It says:
Files under the build folder are generated and shouldn't be edited.
Every time I change the variable and build the project, it returns to the old one.

I want to know if there is any way to edit "BuildConfig.java" file in Android Studio
No. That is generated for you on each build.
However, depending on what it is that you are really trying to solve, you may be able to make changes in your module's build.gradle file that affect what goes into BuildConfig.

Related

How to copy resources files from other directory into Android project during sync or build?

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.

Change build.gradle template file to include libraries upon creation

Whenever I made a new android studio project, I usually have to add the same handful of libraries to my build.gradle file. To save time, is there a way to modify the template for the generated build.gradle file to include these libraries? I found a way to do that for gradlew and for the parent gradle file but not for the app itself. Any help is appreciated.
Cheers!

Android Eclipse only Generate the R file on Demand

Generating of R file works fine for me. But is there a way to get Eclipse to generate just the R file on demand.
Editing a layout file and re-ordering nextFocus attributes crashes the app, unless you regenerate the R file. So I have to clean the project to generate the R file. But my project is very large, and it feels like a waste of time to rebuild the whole project, just for one file. Is there a way/trick to generate just the R.file?
Note:
Build Automatically is checked.
I am working on Library Project, which contains most of the code base for free and paid versions of the app.
Let me reiterate what I understand from your question. Your project is huge and minor changes to a layout result in crashing - owing to rebuilding the entire project. So, you want to know how to build only a part of the project - with the R file instead of rebuilding the entire huge project on minor changes, which crashes.
What you can do is, uncheck the "Build automatically option", make your changes and build manually once all the changes have been made, instead of building the project on every saved change.
I don't think you can generate only the R file since it needs to read all the res files and generate ids for all the resources, excluding none...I don't think that can be done in parts.
There is a way to generate the R.java file from your resources using the Android Asset Packaging Tool (aapt) as stated here (thanks to Pearl for the pointer)
just click on project->buildautomatically to tick
You can't build R.java as per your requirement like it will not build whole project and generate only R.java file.
But let me tell you one thing, R.java file contains resources identifiers. Those identifiers will be generated if and only if project is build. So, you have to build project to stop crashing your project.
You can still unchecked Build Automatically and manually build project by Project -> Build Project option.

Android eclipse project is broken

After switching to my release branch the project had a missing gen file so I added the gen file from java build path.
Now the assets and the res folders are show like gray packages and not folders and I get the errors like res/values/ is missing.
How to return to the standard android project structure in eclipse?
Is there a standard way of returning to the standard Android project. I have become tired to fix project properties and I have tried to clean and restart eclipse It seams that some project metadata is saved the wrong way.
Thanks .
/gen/ folder is automatically generated during compilation. You should include that and /bin/ and also /.properties/ to .gitignore to avoid having to fix properties all the time and also minimise the amount of unnecessary data stored in your repo.

Should R.java be placed under version control

Is R.java file generated by Android SDK on each compile or only when new resources are added using Eclipse? Do I need to put it under version control or not?
The R.java file is generated during resource compilation by aapt tool. You shouldn't add it to source control system.
Also, you should have noted the gen folder where R.java is placed. Your version control system should ignore this folder altogether, not only R.java file inside it. Because this folder is deleted on clean build (not sure about eclipse, but ant script definitely deletes it).
When using Git to control Android projects I add
bin/*
gen/
to .gitignore
You don't need to put it under version control. I think it's on each compile, one every new resource or clean up project.. but need to test to be sure.
I have had projects with R in and out of source control. Both worked.
When the android SDK is loaded into eclipse, it will automatically generate the R.java file. In older versions of the adt, having an incorrect R.java file would give an error, but I believe this is fixed now, and it shouldn't matter either way. If you have the choice though, avoid checking it in.
I would add it to svn:ignore.

Categories

Resources