I have two R generated classes. How do I fix? - android

I originally had my app all in one project. I decided to rearrange things so I could have multiple projects referencing the same code, so I moved a package to a plain java library, and some others to an android library.
The main app originally had two packages;
com.stuff // standard java stuff
com.stuff.android // android specific stuff
When I rearranged, I moved all the com.stuff package to the plain java project and some of the com.stuff.android classes to an android library. The main app now references both.
Now my main app is generating two R classes! One in com.stuff and one in com.stuff.android. The android library has it's own R in com.stuff.android. Neither the android library or app have classes in com.stuff anymore. Only the plain java package has com.stuff package classes.
Both R classes seem to have the same stuff, most of the time. But sometimes weird things happen, and I need to clean all the projects and rebuild to get it to work again, and it's just annoying.
Why is it doing this? How do I fix it?
I am also using subclipse, so maybe it's interfering somehow with all the refactoring

Aha! Found it myself... how come articulating the problem seems to spur new ideas on where to look.
The manifest of the application still had package="com.stuff" instead of com.stuff.android
Some of the layouts still had a namespace reference to com.stuff.
Fixing those two solved the issue.
Edit: And then I thought about this: Changing the package name of an upgraded Android application
Oops.... so looked into my android library, and it was using com.stuff.android in the manifest... So I guess the app was trying to use both? Changed everything back to com.stuff, and now I have one R in com.stuff. Phew!

Related

Add test package to existing Android Studio project

I have an existing android app and I'm trying to implement some junit tests. Normally (with Android Studio 1.2) the test package is created automatically. If I try to manually create folders to mimic the structure I've seen elsewhere there is either no option to create package under those folders, or I can't name it what I should be able to without it being placed under the existing package. Anyone know how to properly add this just as it would have been when auto created?
Every article covering this assumes its already there... like this one:
http://evgenii.com/blog/testing-activity-in-android-studio-tutorial-part-1/
This may not be the best way to do this, but I just created a new project, let it auto-generate the test package, and moved everything from my old project into the new one. There were a few references after the refactoring that needed to be cleaned up but it worked quite well for the most part.

Android ActionBarCompat Not working from the start

OK, I have been wanting to try the new ActionBarCompat, however, I am not able to run my programs in the emulator.
I have been trying to implement the following: http://antonioleiva.com/actionbarcompat-how-to-use.
and have been stuck on basically the first part. However, working with the author of that content, I was able to get further as I was not adding the project under sdk\extras\android\support\v7\appcompat folder like stated. However, I still think that might be the reason I cannot do this...
More detail can be found here: http://antonioleiva.com/actionbarcompat-how-to-use/#comment-43
Basically, on my first attempt, I just created an Android project, and changed the source code as indicated. Code would not run on the emulator. So I went back to the original code, and that ran on the emulator.
Checked online, found out I might need to add the \extras\android\support\v7\appcompat folder as a library to the project I am building. So I added that and a new android project was created. There were build errors from the start, but I failed at trying to add it as a library to my project, and deleted it....thinking this was way overboard.
After back and forth chats with author of linked website, I found out I had to do that overboard thing.
So I tried the following link to the T: (I cannot post more than 2 links due to low repuation...I will add this link as a comment below)
However, Eclipse would not allow me to add the appcompat Existing Android Project...but it did allow me to add the appcompat Existing (General) Project. I think this may be some of the problems??
Right now, I cannot run the project at all. Eclipse is showing a red exclamation mark on the project folder, but all the code seems to be fine. So I don't know what to do now...I recreated this project several times over, and this one was the one where I knew what to do...and I am still getting problems
So...
I decided to move to Android Studio...updated the IDE, updated the SDK manager to include the new support library, and other things. Created a new project, added to the build.gradle file as shown in the link provided below in the comment. I ran the ant build, and then built the project...tried to import the right things to allow ActionBarActivity, but I could not get that far.
I can import
"android.support.v7.*"
"android.support.vy.R" // and all folders within
but nothing allows me to add ActionBarActivity, and I don't know why.
FYI, I guess I would prefer a solution to Ecplise, as it seems like I actually got somewhere with it.
The best example to use is from here, and I would follow it closely. I had similiar issues when I first came across this. Problem was I misunderstood what I needed to do
http://developer.android.com/tools/support-library/setup.html#libs-with-res

Using Custom Libraries

So I'm pretty new to Android Development and I'm curious if I'm missing anything when I'm importing libraries into my android project. I followed this guide on android website and made a new project out of existing code then added it as a library into my own project. The problem is everything errors out, R cannot be resolved as a variable so I tried to clean my project and it does nothing. I import R then it can't find any of my activities. So there's my first problem.
The library I'm using is This Color Picker and really on the homepage it just says to use the xml and add it to my preferences but my preferences doesn't seem to recognize it.
I'm obviously doing something wrong but can't seem to find a decent tutorial to walk me through adding custom libraries to my project. I was hoping someone with more experience could help me find the root of my errors or point me to a tutorial so I can start the import process from scratch.
Am image of my settings file
The library I'm using is This Color Picker
Any library that doesn't publish a complete sample app that uses the library should be ignored, IMHO.
I'm obviously doing something wrong
Presumably, there is no color resource named pumpkin_orange in your project. There definitely is no such resource in the library. Either define this color resource, or replace #color/pumpkin_orange with a literal color or some color resource that you define.
Your R class does not exist because you have bugs in your resources (like the settings.xml one) and/or your manifest. Once those bugs are cleared up, your R class should generate properly.

libgdx and TWL: Android app force closes on any TWL menu, works fine on Desktop

I am implementing menus using TWL (http://twl.l33tlabs.org/) in an app written using Libgdx. The app runs fine if I don't start any menus, but as soon as I go to a menu screen it immediately force-closes. Menu screens work fine on the desktop version.
In which build path should TWL-android.jar be included (right now it behaves the same in main, android, and both)? And how will the program know to use the libraries from this .jar instead of the default gdx-twl.jar? Will I have to manually implement something in code to use one or the other depending on platform?
There does not seem to be any documentation or sample code of anyone using TWL on android, only mentioning that it can be done.
Running debugger attached to phone gives the following logcat error:
Could not find class 'com.badlogic.gdt.twl.Layout' referenced from method com.Nanners.OptionsScreen.<init>
I think that TWL-android.jar should be added to android project's build path too. Location of .jar is not relevant.
When you add TWL-android.jar. As that is Android specific you can't use it on the core project, so the classes you are importing are the ones from gdx-twl. To make it simpler to explain I will divide it in different escenarios.
You add TWL-android to your Android buildpath. But you use Gdx-twl in your core project. Which isn't added. Thus getting a:
Could not find class 'com.badlogic.gdx.twl.Layout'
You add both TWL-android AND Gdx-twl to your build path. Thus getting duplicated classes and:
Conversion to Dalvik format failed with error 1
Solution
If you use TWL-android classes, you can only do it inside the Android project:
Merge Core, Desktop and Android project. Or
Use Interfacing with Platform Specific
If you use Gdx-twl:
Don't do it.
Actually the best solution is to get rid of all twl stuff and use Scene2d.Ui instead. Its crossplatform and much easier to use.

Android: How do I create reusable components?

I've spent a while scouring the net for some sort of information on this, but to no avail.
I'm working on an app for which I needed to create some components, some of which would be likely to have other applications, so I'd like to put them in their own package or project, but am not sure what the correct way to do this is.
So my main project is called something like...
<companyname>.<productname>
And I've called the package for my widgets...
<companyname>.widget
I created a separate project for the widgets and moved the relevant code, layout, resources etc over. That project seems to compile properly, but the main project no longer recognises any references to the widgets.
I added the new widget project to the main project's Project References, but that made no difference.
Any ideas or links to tutorial on how to do this correctly would be much appreciated.
Have you tried setting up a library project?
https://developer.android.com/guide/developing/eclipse-adt.html

Categories

Resources