destroyed gradle file(Module:PackageName) And Not Sync Project - android

I opened my project today and came across this problem:
The gradle (Module: app) file is healthy, but the other gradle file associated with the project is cluttered and corrupted.
The Codes of gradle File(Project: PackageName) is shown below:
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* gradle plugin from the resource data it found. It
* should not be modified by hand.
*/
package android.support.v7.appcompat;
public final class R {
private R() {}
public static final class anim {
private anim() {}
public static final int abc_fade_in = 0x7f010000;
public static final int abc_fade_out = 0x7f010001;
public static final int abc_grow_fade_in_from_bottom = 0x7f010002;
public static fi
This problem does not allow me to continue my work and stop me. Please help me faster. Thank you

You should always use a versioning tools (git, mercury, svn, etc.), even if it is a practice/test project of yours, so that you can recover from these errors
Any case, you can still use Local History to recover this file if you are using Android Studio: https://stackoverflow.com/a/25076685/783707 . Simply go to Project structure, right click your file, click on Local History, and choose an older version of the file to go back to.

Related

Why does my BuildConfig class keeps getting duplicated every time I run my project

I migrated my project to Androidx and every time I run my project I keep getting this error that says class BuildConfig is public, should be declared in a file named BuildConfig.java. I know that the cause of my is that every time I build my project my java BuildConfig class keeps getting duplicated. Which gives it a name such as BuildConfig1, BuildConfig2 etc.. I constantly have to keep deleting it and rerunning my project in order to compile this is really annoying does anyone know the cause of this and perhaps a fix? This is my BuildConfig class
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.examp.smartshop";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
}
Try to clean project(Build->Clean Project) and rebuild Project(Build->Rebuild Project).
or
Try deleting .gradle folder , build folders, .iml file.( You can do thing by going to Project window and choose 'project' option. And do the rebuild project again.
or
last resort File->Invalidate Cashes/Restart.
Vote If it works.
Happy coding.
Thanks.
Under the project search for a folder named ".gradle" and while at it search for another under the 'app' folder named "build". Delete the two folders and run your app. It will solve the issue. See this
The error arises as a result of duplication of files hence Android Studio is unable to determine which files to use.
I had this same issue after doing some package restructuring.
I tried deleting the build and .gradle directories and restarting Android Studio with invalidating caches with no luck.
After the package restructuring, not only did my androidTest files end up in my main directory, eventually I noticed I had ended up with a BuildConfig.java in my source directory. I really should have been more careful with the refactoring preview.
Deleting the BuildConfig.java from my main/java/package directory resolved this issue for me.

Robolectric cannot find AndroidManifest.xml

This test originally ran fine. Checked out a new branch several days later (with commits from many other developers) and it no longer works.
Test class in the mylibrary library module:
import com.company.mylibrary.BuildConfig;
#RunWith(RobolectricGradleTestRunner.class)
#Config(constants = BuildConfig.class, manifest = "src/main/AndroidManifest.xml", sdk = 21)
public class MyTest {
I have also tried:
#Config(constants = BuildConfig.class, sdk = 21)
#Config(constants = BuildConfig.class, manifest = Config.NONE, sdk = 21)
In the library module's build.gradle
dependencies {
.
.
testCompile 'org.robolectric:robolectric:3.0'
Error message when running inside AS is:
java.lang.RuntimeException: build/intermediates/manifests/full/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
Error message when running from command line is:
com.company.mylibrary.framework1.feature1.MyTest > testMethod STANDARD_ERROR
java.lang.RuntimeException: build/intermediates/manifests/full/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
A) Don't know why it is looking there for the manifest
B) That file/directory does not exist
C) src/main/AndroidManifest.xml does exist
Things I have tried:
- deleted the build directory in that library module
- restarted Android Studio
- Build/Clean
- Build/Rebuild Project
- run the test (both inside AS and from command line)
- and tried different versions of the #Config notation
Seems to be in a wonky state that I cannot clear.
I am working on a MacBook Pro. Android Studio 2.0 beta5
You need to set the working directory within the test's run configuration to the module directory.
Well, I've tackled the issue you're facing right now several times and found solution suitable for myself.
Generally, if your test logic does not require access to the application's resources, it's worth using usual RobolectricTestRunner as the time of the test execution is relatively shorter comparing it to the test execution time under RobolectricGradleTestRunner.
If, for some reason, you need access to the specific AndroidManifest.xml file, IMO it's better to come up with test file rather than to operate on the project's one.
By saying 'test file' I mean the following:
Let's start by defining what are the methods that can help us to obtain path to the resources files. The goal is to be able execute tests under Android Studio and, what's more relevant, via CLI (gradle :project:testBuildTypeUnitTest)
Java's System class: System.getProperty('user.dir') returns User's current working directory. Obtaining current directory we are in may help us to obtain paths to the resources we need to run our test having them provided.
Overriding RobolectricGradleTestRunner. To create our customized test runner we need the AndroidManifest.xml, the res directory and the assets directory paths:
public class CompassApplicationRobolectricTestRunner extends RobolectricGradleTestRunner {
private static final int TARGET_SDK_VERSION = Build.VERSION_CODES.LOLLIPOP;
private static final int MIN_SDK_VERSION = Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
public CompassApplicationRobolectricTestRunner(Class<?> klass) throws InitializationError {
super(klass);
}
#Override
protected AndroidManifest getAppManifest(Config config) {
final String manifestPath = PathResolver.resolveAndroidManifestPath();
final String resourcesPath = PathResolver.resolveResPath();
final String assetsPath = PathResolver.resolveAssetsPath();
AndroidManifest manifest = new AndroidManifest(
Fs.fileFromPath(manifestPath),
Fs.fileFromPath(resourcesPath),
Fs.fileFromPath(assetsPath)) {
#Override
public int getTargetSdkVersion() {
return TARGET_SDK_VERSION;
}
#Override
public int getMinSdkVersion() {
return MIN_SDK_VERSION;
}
};
return manifest;
}
}
Below, is the link to the example that worked for me. It was developed, however, some time ago and from the time perspective I see it can be done more elegant way so if you decide to apply this solution to your project, organize your path constants to be static and immutable:
https://github.com/dawidgdanski/android-compass-api/blob/master/app-tests/src/test/java/pl/dawidgdanski/compass/PathResolver.java
It's worth remembering that File.separator returns system's default directories separator. It's extremely useful when it comes to provide system-independent paths separated with default separation symbol.
Eventually, if the solution described above is not the one you want to follow, read decent article about setting up testing environment available here:
http://artemzin.com/blog/how-to-mock-dependencies-in-unit-integration-and-functional-tests-dagger-robolectric-instrumentation/
Hope that solves your problem.
In my case, I was running a single test manually (Right click and run) from inside Android Studio and Roboelectric wanted a RELEASE version. The question above was about debug but my test runs for some reason wanted a release version of the manifiest.
java.lang.RuntimeException: build/intermediates/manifests/release/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
I had never done a production build in this project so that build directory had never been created.
After wrestling for a bit with no success (setting the path in configuration, trying to get the path in my CustomRoboelectric file), I just generated a production build so that I had the release path created with a manifest and everything worked.
So my solution was to just run the build to create what Roboelectric wanted.

Android studio keeps adding illegal line to R.java

I'm coding an Android app and so I put a 0.gif image to all the drawable-XXXX folders. When trying to build, android studio threw an error:
/Users/ziga/Desktop/GimVic-suplence-android/app/build/generated/source/r/debug/com/zigapk/gimvic/suplence/R.java
Error:(28, 32) error: expected
Error:(28, 34) error: illegal start of type
Error:(28, 35) error: expected
After googling, I realized that this is caused, by this code in R.java:
public static final class drawable {
public static final int 0=0x7f020000; //here is an illegal statement
public static final int bg_card=0x7f020001;
public static final int bg_card_green=0x7f020002;
public static final int ic_launcher=0x7f020003;
public static final int ic_launcher_web=0x7f020004;
public static final int santa0=0x7f020005;
public static final int smile=0x7f020006;
}
I renamed my image to santa0.gif and tried to build again: same error was thrown :/
Thew I tried to erase this line and build again: same problem occurred.
What to do??
Thanks in advance :)
I put a 0.gif image to all the drawable-XXXX folders
Resource names need to be valid Java data member names. Java data member names cannot start with a number.
I renamed my image to santa0.gif and tried to build again: same error was thrown
If I had to guess, you did not rename all copies of 0.gif, but only one.
Usually when such weird problems occur, cleaning the project helps. That can be done with the following menu options in Android Studio.
Build -> Rebuild Project
Build -> Clean Project
Ctrl + Shift + F (Windows) search for "0."
Cmd + Shift + F (Mac)
You will find it if it exists.

Resource.Layout.filename is returning the wrong layout file

I have a MonoDroid application project (let's call it mainApp). This references app.Screen project, which is a MFA library project. Initially, my activities were in the mainApp project. Everything was working fine. I needed to put some Activities (and resource, drawables, etc) in the app.Screen project.
I have moved all the resources I need to the app.Screen project. It builds fine and in my activities (which are sitting in app.screens) I can access Resource.Layout.filename and even Layout.Id.name.
However, when I run the application, in SetContentView(Resource.Layout.filename) I get the wrong layout file . This causes FindById<Button>() to return null obviously because it does not have these buttons in this layout file.
I found that same Layout file has different Id in my MFA library project than what is in the mainApp project like this:
// In the mainApp project
public partial class Layout
{
// aapt resource value: 0x7f030001
public const int DeliveryScreenLayout = 2130903041;
// aapt resource value: 0x7f03000a
public const int splash_screen_layout = 2130903050;
private Layout()
{
}
}
// in app.screen library project
public partial class Layout
{
// aapt resource value: 0x7f030000
public static int has_hello_layout = 2130903040;
// aapt resource value: 0x7f030001
public static int splash_screen_layout = 2130903041;
private Layout()
{
}
}
I am using VS 2010 with MFA 4.0 and my projects are targeting Android 4.0. I have tried Clean & Build, Removing /Bin and /Obj folder, with no luck.
Any help would be much appreciated.
This appeared to be a bug in MonoDroid, here is the link to the bug in Xamarin bugzilla
This is caused by the Resource.Designer.cs in the MFA library project has a different ID (int) values than what the main project has in its Resource.Designer.cs file.
I have worked out a workaround for it. In my mainApp I manually call mainApp.Resources.UpdateIdValues(); and that would update the Resources id values in the other MFA library projects
Xamarin said that this bug was resolved in 4.6.4. I have not tested this fix though

R.java problems with generating

I tryed to create new project and in my R.java there was next code, for example:
public static final class layout {
public static int activity_main=0x7f030000;
instead of
public static final class layout {
public static final int activity_main=0x7f030000;
So I can't build project normally, because it generates public static int without final.
What should I do?
Right Click on project --> Android Tools -->fix project properties
before doing this remove import statement like
import android.R.*..
or try clean project from
project --> clean
This could be because of many things.
1. Check your xml files have no errors in them as this can stop R.Java from being automatically generated.
2. Clean your project. This will rebuild your project.
3. Delete any android.R import statements.
4. Close and re-open eclipse.
I also wouldn't recommended fiddling with the R.Java file dirctley.

Categories

Resources