All,
I am attempting to use an existing open-source project (we'll call it A) within my app as a library. Project A also comes with its own library project (B). Project A compiles and runs just fine; however, when I try to use A within my app (I checked the 'Is Library' within A and added A to my app) I get several errors that "No resource identifier found for attribute 'X'in package..." These particular attributes exist within B. I even checked that they were added to R within A, and in fact, they were.
My question: why doesn't my app see that these resources exist?
I've searched all over and found only one situation like mine:
Android library not pulling its resources through to other projects
but I do not see that any of my resources are named the same.
I'm using Eclipse with ADT v20.0
I appreciate any help!
EDIT: If it's helpful, the open-source app I'm trying use is AnySoftKeyboard (ASK). I've also tried creating a new project and adding ASK as a library -- no dice.
EDIT2: Part of making ASK a library required converting several switch statements to if-else statements because R Ids are not declared as final for libraries.
The errors are apparently due to the usage of custom attributes in the AnySoftKeyboard project that you converted to a library. I found that a solution is recently added into ADT (on Rev 17), mentioned in this answer.
As instructed, I tried replacing all instances of
"http://schemas.android.com/apk/res/com.menny.android.anysoftkeyboard"
with
"http://schemas.android.com/apk/res-auto"
in the newly converted library project and was able to build and run an app which includes the project (didn't really test any functionality though).
Hope this helps.
Related
I have the following project structure which I want to convert to a instant apps. The installed project works fine, but when I want to runt the instant app version, the base feature module loads perfectly, but when it comes to the feature module, then it fails to find the resources from its module. When I move the resources from feature module to base module, then it recognizes them with the full package name of the base feature module.
The project structure is the following:
- app module
- instant app module
- base feature module - com.app.base.feature
- feature module - com.app.feature.
in feature module when the resource is located in feature module itself the resources are not found, but they are found when I move the resource into the base feature module and reference them as following com.app.base.feature.R.layout.sample_layout.
EDIT: No known package when getting value for resource number 0x80060009.
Any kind of help would be appreciated :)
When you modularise your app, the base feature module cannot access any classes or resources present in the feature module. However the vice versa is possible.
It might so happen that when you create the fragment, the R class might be pointing to the base module. Try specifying the full path to the feature module R class while accessing the layout and check if it solves your issue. Just go through all your R class references and specify full paths to base and feature R classes wherever necessary.
It is actually a bug of the canary version.
We already discussed it here: stackoverflow question
We opened a bug on the official Android Studio tracker in which I provided more informations: bug tracker
Please do not hesitate to star it to make Google prioritize the fix (currently P2).
With further experimentation I noticed that:
So if we have a project with 4 modules:
base
f1
f2
f3
f3 instant module (the last one in alphabetical order) will works correctly and will link all of its own resources correctly.
f1 and f2, on the other hand, will use resources from f3 module instead of their own and hence either they crash or their layout / images / strings got really messed up.
Finally problem occurs only for resources to resources references trough XML (i.e. reference a drawable from a layout or establish a constraint between two elements of a layout).
Hence:
<ImageView android:src="#drawable/icon"/> --> will shows the
problem
But in java image.setDrawable(R.drawable.icon) --> will work
correctly
ALSO, concerning your EDIT 1:
there is a second bug that I also reported in a second tracker here: bug tracker. In this case if you add a XML tag in your layout or a fragment that use an XML TAG in their layout. Instant app will crash. Please star the bug if you find out this is also the cause for you.
The latest build-tools have been patched in with a fix for this issue.
Please update your Android SDK Build-Tools to 27.0.2 version.
Ensure you are on Android Studio 3.0.1 or newer.
The Google issue tracker post regarding the Android Instant Application error crash has also been updated.
Note: Bug link: issuetracker.google.com/issues/62935326 might also be resolved in the latest Android Build-Tools 27.0.2 roll-out, since it is also related to missing/misreferenced resources.
I found this problem similar problem when I created a project with Instant App and Kotlin support without Support Library. The Android Studio intellisense din't add the correct import for the Resources. So, I changed that import:
import com.company.awesomeapp.feature.R
For this:
import com.company.awesomeapp.R
And everything worked fine. My thought is: for modular apps, the intellisense doesn't know what is the correct reference, so, the project broken in the compile time.
I've got an Android project that includes references to a library project. The library project contains a resource (a renderscript bytecode package). The main project also has it's own resources, including a layout, which contains a field that looks like this:
<EditText android:id="#+id/edit_name" />
When I build my main project in ant, and I call findViewById(R.id.edit_name) at runtime, the call returns the EditText component I expect. But when I clean the projects and build them in Eclipse findViewById(R.id.edit_name) returns null.
Debugging the call shows that my component is present in the View at runtime, and actually has an id assigned, but it's not the same id as the value of R.id.edit_name (in this case, the id in R.java and the runtime value of R.id.edit_name == 0x7f070000, whereas the actual View that exists at runtime has mId == 0x7f080000)
With the ant build, R.java is created with R.id.edit_name === 0x7f080000 (which matches the id I observe when running the app.)
When I remove the library dependency in Eclipse, R.java contains R.id.edit_name == 0x7f070000, but so does the runtime, and everything works just fine.
I realize one good answer is to file a bug report with ADT/Eclipse, and use ant to build, but I'm developing the library and I want to be sure that it supports Eclipse users. So what I'm wondering is:
Are there known bugs in Eclipse that can cause this sort of thing? Are there known workarounds?
If not, what is the next debugging step?
Edit:
It turns out this is associated with using a Renderscript asset- when I remove the renderscript, the problem disappears (both projects use the 07 "type" tag in their ids.) I'd still totally love to hear about a workaround, but for now it looks like custom renderscripts in Eclipse built library projects is a non-starter. For reference, I'm using the latest and greatest Eclipse ADT (22.2.1)
You will really make my day by explaining the following nuissance.
L is a library. A is an application using L, CA is a class, declared in A extending a class CL in the library L.
Untill recently, I could just place L.jar in the lib folder of A project. But I purchased a new hard disk, reset Eclipse, ADT plugin and SDK, then transferred my project to the new location. This is when it started.
If I place in A a reference to the project L (via Project/Properties/Android/Library), everything still works all right. But with a jar file, it gives a "No Class Defintion Found" error for CA class, even though it belongs to the same class as the calling method!
To avoid some sceptical remarks:
L has no resources in it.
Compiler version is 1.6
I cleaned both projects millions of times.
Both projects are compiled with same API version.
No obfuscation was used and I checked that CL class is really present in L.jar.
Tried placing L.jar in build path, as topmost, then as bottommost - no help.
Thank you for anticipated help.
It was rather silly of me: in "Order and Export" panel of BuildPath configuration I had Android Dependencies ticked, but Android Provite Libraries unticked.
What I found out is that libraries linked through Android properties go to Android Dependencies, whereas the ones in lib folder are considered as Android Private. This explains why the first were included, while second weren't.
The most annoying thing is that Eclipse doesn't complain, the build seems to be all right, and only at the execution stage the error comes out. As a C programmer I am not quite used to that :)
I added johannilsson-android-actionbar as a library to my project. It worked well, and everything was good for me. But recently, I have added the uitableView as a library and got this error:
/--mypath--/actionbar/res/values/attrs.xml:19: error: Attribute "tittle" has already been defined
And the R is not Known, so I cannot reference my XML. I have ADT 17 and Eclipse 3.7. I tried to remove the uitableview, and the project works fine, no Errors, and R is OK.
The authors of libraries need to take steps to avoid collisions on resource IDs. The authors of your libraries have not, apparently.
One possibility is to switch from johannilsson-android-actionbar to ActionBarSherlock and see if you have better luck.
I am working on a custom Android library. I start off with a java project (in Eclipse) with another UI testing Android project.
In my UI testing project, I reference the library project in build path, and everything is good and I can test the library codes in the UI.
Later on, I decided I need to have the 'Gen' code (for custom styles attributes), so I try to change my library to an Android project (via Android-tools -> convert.. ), and disasters happens! After fixing up all the compile time problems, it finally 'let' me start the UI testing application, and bangs! When I try to create any objects from the library class, it said (in the Log) that Class not found.
Two questions:
Any idea how to fix this? I tried but seems it is for referencing another .apk that need to install separately.
If I just keep it to be java project (not android) for my library, can I use the resource generator? and how?
PS: the dependency (my library) is installed before the UI test application, according to the Console of Eclipse said.
Update: I tried to compile the library project to jar and reference it from the UI testing, and in this way, it works. But I don't want to use this approach since it is very slow in terms of testing.
for those who are doing same mistake like me
when library project is an android project
got to
properties > android > click add button at bottom of the popup inside
library section
and add project, instead of
properties > java build path > project > add
later approach is for pure java projects only .
Finally I found the answer to my own question. This is actually mentioned in official documentation.