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
Related
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.
Firstly thanks to Mark Murphy, regarding comment 10 and the link to a really blank activity template in Android Issue 67513
Now the question regarding the new template: Is it intended that it should still create a new appcompat_v7_n+1 library project?
When I tried it, one was created. I deleted it, removed the reference from the blank activity project, then had to delete references to appcompat styles in the values folders and a style in the manifest.
Don't get me wrong, doing that was no big deal and it's a vast improvement but I'm wondering if that was intended.
Is it intended that it should still create a new appcompat_v7_n+1 library project?
Crap.
The new-project wizard adds some of that. I thought it was all in the new-activity wizard, which also adds some of that when using the stock templates.
I'll need to fork the NewAndroidApplication template to get rid of those bits. I'll work on that. I've added a note to the project README in the interim.
Thanks for pointing this out!
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
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.
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!