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.
Related
Noob Android Studio 3.6.1 on Mac Mojave developer here. I have a very simple app with a few activities. Every so often, the Kotlin class for one of the activities will complain of an unresolved reference to the corresponding layout XML file.
For example, in the Kotlin Class (TraceActivity.kt), I have the following code:
setContentView(R.layout.activity_trace)
and the corresponding XML file lives at:
MyApp/app/src/main/res/layout/activity_trace.xml
All pretty standard stuff I reckon. But setContentView would complain that it couldn't resolve activity_trace. This has happened on a few occasions, and I discovered that restarting would resolve the problem. But this morning, it isn't helping. And it's also started complaining about some of the strings I've added to strings.xml
I managed to get round the errors by making use of the full names for each of the items e.g.
com.mysite.myapp.R.layout.activity_trace
and
com.mysite.myapp.R.string.my_message
So my guess (as a noob) that somewhere it's losing track of where it is. And yet my other activities are perfectly happy when I omit the full location. Can anyone offer some insight here? Thank you - SO is awesome.
So I am trying to work through the example here:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/SurfaceViewOverlay.html
and on the last import line it says
//Need the following import to get access to the app resources, since this
//class is in a sub-package.
import com.example.android.apis.R;
Question is where do I get the package that contains this? I found very little info online and obviously don't have it already since it's underlined red when I type it. I know this is probly a noob question but hey we all start somewhere...
Try to run this example using the android sample app.
To install and run the Android Sample apps follow the instructions here:
http://developer.android.com/resources/samples/get.html
To help you get started quickly, the Android SDK includes a variety of
sample code and tutorials that illustrate key concepts and techniques
of Android application development. For example, the samples show the
structure of the manifest file and the use of activities, services,
resources, intents, content providers, and permissions. They also show
how to add specialized capabilities to your apps, such as Bluetooth
and Contacts integration, multiple screens support, Live Wallpaper,
and more.
That R file is simply the R file of your project. So it will be your.project.main.package.R depending on the package attribute of the <mainfest> tag in your AndroidManifest.xml.
So if you have imported the project sample from the SDK, the R file would be in the same package as the example, i.e. com.example.android.apis.
However, if you are using the code in your own project as I assume is the case because you have mentioned the import remains unresolved, then you have to import the R file for your own project. Note that you will also have to import the required resources (layouts, drawables, etc) into your project from the sample.
In my case, I was getting this error because I needed to add the:
C:\adt-bundle-windows-x86_64-20130729\sdk\add-ons\addon-google_apis-google-18\libs\maps.jar
to the Libraries tab in the BuildPath section of "right-click over project" / Properties.
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!
I am just starting off with android and have been googling high and low to find any tutorials/resources that could answer my beginners questions.
How can import a third party resource into my project and start using it?
For example, i wanted to use scrollableTabActivity, a widget that's available at https://github.com/honcheng/ScrollableTabHost-for-Android. I have downloaded and it looks like it is a project by itself. How can import into into my project and start using it?
This is the case of even projects like droid fu, for the life of me i could not figure out how to add them and start using in my project.
I did successfully added asynchttp into my project cause there was .jar download available. But for projects like droid-fu or scrollableTabActivity, how can i use the source files to add the functionality into my project?
Any help is highly appreciated
Thanks
Add the projectyou downloaded to you workspace.
Right click on it, properties, Android and be sure the Is Library checkbox is checked.
Then in your project, right click, properties, Android and click on add on the bottom right to add the previous project.
The project you refer to actually contains a lot of demonstration code which shows you how to use the ScrollTabHost control in your app. Rather than trying to include this stuff which will just bloat your app, simply copy the ScrollTabHost.java file in to your project, along with any resources upon which it depends.
I agree with Mark Allison's answer. But generally speaking to import a whole project in Eclipse, check the box next to that third party project name on the Project References tab in your project Properties.
I am trying to add the LVL library project to my application's project. It should be simple and straightforward, but it isn't:
When I click the Add... button, I receive the Library Project Selection dialog as expected:
I select it and it is being accepted with the green checkmark next to it.
However, when I re-open that Properties > Android box again, it gets a red X next to it, making it unusable:
There is an excellent answer documenting the "delicate behavior" of referencing a library project, but despite implementing the tips there (same root directory), I am still having this problem.
How do I solve (or workaround) this problem?
Is there a way to make Eclipse/ADT use fewer..\..s to represent the path of the referenced library project? (all is needed to reference that library correctly is ..\..\thisisinsane\library, there really is no need for all that ..\..\..\..\..\..)
I solved the problem by following the excellent steps in this answer.
In essence, The Eclipse+ADT duo doesn't "like" projects that aren't in the workspace, regardless whether these are application projects or library projects (even if Google created them).