My project contains these two libraries , but for some reason I get an error when I want to run it on my device :
The error is as follows:
workspace_desarrollo\Librerias\FloatingActionButton\res\values\attrs.xml:6: error: Attribute "color" has already been defined
Look at both libraries and found that both are defined . What I did was rename the FAB library and reads as follows:
<attr name="colortem" format="color"/>
Everything normal, but when you run the APP , the button shows me with white background. There are 3 buttons that use and puts three white background.
Previously I did not have this problem, but I had to change PC and when you import the new workspace projects started dating this error.
The appcompat_v7 this in : target=android-21
The FloatingActionButton this in :
target=android-19
android.library=true
android.library.reference.1=../nineoldandroids
My project is in :
target=android-21
android.library.reference.1=../../Librerias/FloatingActionButton
android.library.reference.2=../../Librerias/appcompat
android.library.reference.3=../../Librerias/google-play-services_lib
I hope you can help me.
Thank You
PD : I'm thinking about starting to develop android studio , but I'm not entirely convinced
Remove the colortem attribute definition, the other one will be used. Otherwise you'd have to change all R.attr.color references inside FAB library to R.attr.colortem as well.
Related
I'm trying to use the Runtime Resource Overlay (RRO) mechanism to overlay an xml resource, which is using custom attributes and custom namespace. When building the overlay APK the aapt2 (link) throws an attribute not found error.
How do I make known the custom attribute from the main application to the overlay?
Is it even possible to use custom attributes in an overlay?
Details:
The overlay contains of two files:
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.test.simpleappoverlay">
<overlay
android:targetPackage="de.test.simpleapp"
android:targetName="Test"/>
</manifest>
and the xml file res/xml/my_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<MyConfig xmlns:app="http://schemas.android.com/apk/res/de.test.simpleapp"
app:text="hello">
</MyConfig>
<!-- I also tried: xmlns:app="http://schemas.android.com/apk/res-auto" -->
The main application defines the attribute text in res/values/attrs.xml:
...
<declare-styleable name="MyConfig">
<attr name="text" format="string" />
</declare-styleable>
Furthermore it defines the overlayable tag in res/values/overlayable.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<overlayable name="Test">
<policy type="public">
<item type="xml" name="my_config"/>
</policy>
</overlayable>
</resources>
To build the overlay I do this:
aapt2 compile -v --dir app/src/main/res/ -o SimpleAppOverlay.flata
and
aapt2 link -v --no-resource-removal
-I ~/Library/Android/sdk/platforms/android-29/android.jar
--manifest app/src/main/AndroidManifest.xml
-o sao.apk SimpleAppOverlay.flata
Which leads to the following output:
note: including /Users/bernd/Library/Android/sdk/platforms/android-29/android.jar
aapt2 W 09-01 14:33:06 20083 694697 ApkAssets.cpp:138] resources.arsc in APK '/Users/bernd/Library/Android/sdk/platforms/android-29/android.jar' is
compressed
note: linking package 'de.test.simpleappoverlay' using package ID 7f note: merging archive SimpleAppOverlay.flata
note: merging 'xml/my_config' from compiled file app/src/main/res/xml/my_config.xml
note: enabling pre-O feature split ID rewriting AndroidManifest.xml:
note: writing to archive (keep_raw_values=false)
note: writing AndroidManifest.xml to archive
note: linking app/src/main/res/xml/my_config.xml (de.test.simpleappoverlay:xml/my_config)
app/src/main/res/xml/my_config.xml:2: error: attribute text (aka
de.test.simpleappoverlay:text) not found
error: failed linking file resources.
I had a similar problem to this where I was trying to overlay an app with custom attributes in Android 10 and have a solution. There are two changes that are needed:
Part 1
It looks like your app name is de.test.simpleapp so your my_config.xml file should look like:
<?xml version="1.0" encoding="utf-8"?>
<MyConfig xmlns:app="http://schemas.android.com/apk/prv/res/de.test.simpleapp"
app:text="hello">
</MyConfig>
The important piece is specifying the 'prv/res/app.packagename' so it uses the namespace of the base app for the private attributes. If you used 'apk/res-auto' that would not work as it resolves to the name of your app (which in this case is the overlay app de.test.simpleappoverlay) which does not contain the definition of the private attributes.
Part 2
Since you now have a dependency on the main app when linking, you have to include it in the link command with a -I simpleapp.apk (or whatever the APK name is of the base app). Right now you are just including android.jar in the aapt2 link step which only contains the 'android' namespace and attributes. Therefore, you now need to add your base app in the include step so it can link properly against its namespace and attributes.
Like some of the other answers said though, this problem goes away in Android 11, but if you're stuck on Android 10 like I am hopefully this helps.
I don't think including new ids is supported in the current implementation of the RROs (at least in Android Q).
Regarding your error, aapt uses the android.jar to generate the apk for your overlay. Since it cannot find your new attribute, it throws an error. For this to work I believe you would need to use a modified android.jar including your attribute. One way of doing this is by modifying the Android SDK in the AOSP and creating your own version that you would then use for the aapt command.
Some time ago I switched my AOSP environment from Android 10 to 11. Google made quite a few changes to the Overlay mechanism. To my big surprise these changes fixed the problems I had when trying to "overlay" custom attributes.
With the Android 10 environment I observed while debugging that the Android XML parser returns "null" when trying to read the mentioned attributes. With idmap I was able to confirm that the attributes were present in the overlay and the target app, and that they were properly mapped.
Also all the linker errors were gone.
I have a react native application and I changed the package name of the application using https://www.npmjs.com/package/react-native-rename. After that I tried to run the project but its saying that the application is not registered. I have tried the following steps also.
Opened the project in android studio and make sure that the package name is changed and all the files are also in the same package name.
Tried cleaning the old gradle files.
Uninstalled the previously installed version of the app (The one which have the original package name.
Any help would be appreciated. Thanks in advance
You need to check 2 files to make sure you have equal names there:
index.js -> application name in the last line:
AppRegistry.registerComponent('YourAppName', () => App);
app.json -> name property
In both places names should be equal (case sensitive).
Have you changed the values in the index.ios.js, index.android.js and app.json files?
There are some instructions here.
android\app\src\main\java\com{someFolderName}\MainActivity.java
you landed up on this answer because still you are not able to solve the issue
open the file mentioned in above in title
this used for
Returns the name of the main component registered from JavaScript.
This is used to schedule rendering of the component.
look for method
#Override
protected String getMainComponentName() {
return "AddYourNewNameHere";
}
which might be returning a hard coded string replace it to desired name!!
EXTENDED TIP
ensure you clean your gradle demon as the project does not compile sometimes
for that use following
cd android
gradlew clean
I am using Eclipse 4.2 with Android SDK.
I am wondering if it is possible to change the default package ID com.example that shows in the "New Android Application" wizard as you type the application name?
I would like it to default to my own package ID so that I don't need to correct the Package Name field each time.
Is this possible to do? Please explain how.
No, you cannot change the default; it's hardcoded in the plugin sources.
(For the curious, it's in com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectPage#SAMPLE_PACKAGE_PREFIX in the ADT code base). We should consider persisting the most recently set package prefix and inserting the parent package next time. Feel free to file an issue for that at http://b.android.com category Component-Tools.
-- Tor
With Android Studio not running, edit the file: C:\Users\MyAccount\.AndroidStudio\config\options\options.xml (replace C: with the installation drive and MyAccount with your account name).
Within the xml file look for "property name="SAVED_COMPANY_DOMAIN" value=" and change the value to what you want.
Following user2232952's guidance, for new versions of Android Studio change the value of:
<property name = "SAVED_ANDROID_PACKAGE" value = "com.example" />
I'm not sure why so many people have right answers with wrong file location...
I've installed android studio 2020.3 with all default settings and the file others.xml is in folder
C:\Users\MYUSER\AppData\Roaming\Google\AndroidStudio2020.3\options
For anyone coming here in 2020, the file you are looking for is other.xml
It can be found in your AndroidStudio library under config/options/other.xml
(For mac this is probably ~/Library/Application Support/Google/AndroidStudio4.1/options)
Then you can follow the instructions by #Murillo Comino
<property name = "SAVED_ANDROID_PACKAGE" value = "com.example" />
EDIT:
As per #Douglas Kazumi 's comment, it is important that AS will be closed while editing this.
If you've already created your project, you could go to your AndroidManifest.xml file and update the attribute in the Manifest (root) tag
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.package.name"
android:versionCode="1"
android:versionName="1.0" >
Just make sure the rest of your code also reflects this change.
Click the package name and hit Alt+Shift+R and Rename, it will update everything!
this is related to my previous question. I'm trying to build Phone application from android 4.0.4 using maven (I'm adding framework_intermediates as dependency, so internal apis problems are solved), and I ran into this problem. Some parts of the logs are as follows:
Phone/src/com/android/phone/CallNotifier.java:[601,32] cannot find symbol
symbol : variable EventLogTags
(the corresponding line in CallNotifier.java is: EventLog.writeEvent(EventLogTags.PHONE_UI_MULTIPLE_QUERY); )
Phone/src/com/android/phone/InCallScreen.java:[723,28] cannot find symbol
symbol : variable EventLogTags
(the corresponding line in InCallScreen.java is: EventLog.writeEvent(EventLogTags.PHONE_UI_ENTER); )
So... it cannot find the class EventLogTags. There is actually a file Phone/src/com/android/phone/EventLogTags.logtags which has the following contents:
# See system/core/logcat/event.logtags for a description of the format of this file.
option java_package com.android.phone;
70301 phone_ui_enter
70302 phone_ui_exit
70303 phone_ui_button_click (text|3)
70304 phone_ui_ringer_query_elapsed
70305 phone_ui_multiple_query
Apparently, this file tells the system to use some particular tags to log important events in the system. I did a full grep, but could not find any file which defines the values PHONE_UI_ENTER, PHONE_UI_MULTIPLE_QUERY, etc. These are just logs, so I could just comment out these and get it working. But I don't want to do this because I need to build this inside the entire aosp later on. So my question is, how do I get this to compile using maven, without modifying any file?
The Android build system code-generates a Java class out of .logtags files if needed. See: https://github.com/android/platform_build/blob/master/core/base_rules.mk
You will need to decipher the make rules and run that code generation yourself, I imagine.
I'm making couple of Android library apps for a project. To simplify the question, let's say I have two libraries(utilLib, screenLib) in this project(now will be referred to as app).
There's String resource with the same name inside each project but with different values. Like this:
utilLib
<string name="app_version">1.0</string>
<string name="hello">UtilLib Hello</string>
screenLib
<string name="app_version">0.7a</string>
<string name="hello">ScreenLib Hello</string>
app
<string name="app_version">0.1</string>
I realized that I can refer to the string using com.package.R but what if my code looks like this what will show up?
<!-- language: java -->
import com.app.R;
...
private void checkValue(){
String version = getString(R.app_version);
Log.d(TAG, "version: " + version); // 0.1 show be here
String hello = getString(R.hello);
Log.d(TAG, "Hello: " + hello); // <---- ? ('UtilLib Hello' or 'ScreenLib Hello')
}
I am trying to make modular build here but don't fully understand how Android prioritize its R.java to use. Has anyone had experienced with this?
Log.d(TAG, "version: " + version); // 0.1 show be here
Reason quoting from official dev guide Managing Projects - Library Projects:
When you build an application that depends on a library project, the SDK tools compile the library into a temporary JAR file and uses it in the main project, then uses the result to generate the .apk. In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library project is not compiled into the application .apk. This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.
Log.d(TAG, "Hello: " + hello); // <---- ? ('UtilLib Hello' or 'ScreenLib Hello')
This is determined by library project priority.
Quoting from official dev guide Managing Project -Library Projects:
Resource conflicts
Since the tools merge the resources of a library project with those of a dependent application project, a given resource ID might be defined in both projects. In this case, the tools select the resource from the application, or the library with highest priority, and discard the other resource. As you develop your applications, be aware that common resource IDs are likely to be defined in more than one project and will be merged, with the resource from the application or highest-priority library taking precedence.
Quoting from official dev guide From Eclipse with ADT - Referencing a library project:
If you are adding references to multiple libraries, note that you can set their relative priority (and merge order) by selecting a library and using the Up and Down controls. The tools merge the referenced libraries with your application starting from lowest priority (bottom of the list) to highest (top of the list). If more than one library defines the same resource ID, the tools select the resource from the library with higher priority. The application itself has highest priority and its resources are always used in preference to identical resource IDs defined in libraries.
Quoting from official dev guide From the Command Line - Referencing a Library Project:
If you are adding references to multiple libraries, note that you can set their relative priority (and merge order) by manually editing the project.properties file and adjusting the each reference's .n index as appropriate. For example, assume these references:
android.library.reference.1=path/to/library_projectA
android.library.reference.2=path/to/library_projectB
android.library.reference.3=path/to/library_projectC
You can reorder the references to give highest priority to library_projectC in this way:
android.library.reference.2=path/to/library_projectA
android.library.reference.3=path/to/library_projectB
android.library.reference.1=path/to/library_projectC
I can't find any word that can explain this more clear than official dev guide.
you will have to import com.screenLib.R and com.utilLib.R
In your code it should probably throw an error "cannot resolve hello"
Lemmme know if this is right!!!!