android material design sample code giving missing resources errors - android

I am trying to run android material design same taken from below https://github.com/material-components/material-components-android
but getting these errors :
failed
:lib:packageDebugResources
tokens.xml
Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_sys_color_dark_surface_tint">?attr/colorPrimary</macro>'
fab_tokens.xml
Can't determine type for tag '<macro name="m3_comp_fab_primary_container_color">?attr/colorPrimaryContainer</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_comp_switch_selected_icon_color">?attr/colorOnPrimaryContainer</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_sys_motion_path">linear</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_sys_shape_corner_full_family">rounded</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_ref_typeface_brand_regular">sans-serif</macro>'
/Users/mac/AndroidStudioProjects/material-components-android/lib/java/com/google/android/material/bottomappbar/res/values/tokens.xml: Error: Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'

I got the same error when upgrade to this version
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.8.0-alpha01'
But working fine in
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'

Problem is solve after using current version of android studio ( updated from 4.2 to 2021.2.1 and used recommended gradle plugin )
Got the below reply from github when i open defect for same
"The error message you attached says not recognizing resource tag, which requires AGP 7.2. You must use a version later than 1.7.0-alpha02, please make sure your app build with the minimum required plugin versions."

updating the Android Gradle plugin to 7.3.3 (gradle-7.3.3-bin.zip)
things will be ok.

Replace :
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
with:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
in build.gradle(:app) file under dependencies { }

Try downgrading material design library in build.gradle(app).
I have changed
implementation 'com.google.android.material:material:1.7.0'
to
implementation 'com.google.android.material:material:1.6.0'
And this resolved my issue.

This issue should be relevant to people who dig deeper and do not directly work with these dependencies, as it works fine for building and running apps in Android Studio.
It seems that material 1.7.0 is using illegal tag <macro>, you can see it in multiple files when looking through their release changes, specifically the **/tokens.xmlfiles. I could not find any information about this tag in AGP documentation and the only references to it I found from this git repo was this part of the code
private fun parseMacro(
element: StartElement, eventReader: XMLEventReader, parsedResource: ParsedResource): Boolean {
...
// Macros can only be defined in the default config
val defaultConfig = ConfigDescription()
if (parsedResource.config != defaultConfig) {
logError(
blameSource(source, element.location),
"<macro> tags cannot be declared in configurations other than the default configuration")
return false
}
So I'm not really sure how did they work around it.
In the future it is possible that AGP will support this tag externally and include it in their documentation, but for now you'll have to use workarounds

Related

Jetpack Compose. Preview is not available

There is a project with compose.
There are a 2 modules in the project: core and othergames (core is depends on othergames).
I can successfully see a previews (annotated with #Preview) of compose views in core module. But when I try to see previews in othergames, preview can't be shown with error:
The following classes could not be instantiated:
- androidx.compose.ui.tooling.ComposeViewAdapter (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout.
There are details:
java.lang.NoSuchFieldError: view_tree_saved_state_registry_owner
at androidx.savedstate.ViewTreeSavedStateRegistryOwner.set(ViewTreeSavedStateRegistryOwner.java:53)
at androidx.compose.ui.tooling.ComposeViewAdapter.init(ComposeViewAdapter.kt:666)
at androidx.compose.ui.tooling.ComposeViewAdapter.<init>(ComposeViewAdapter.kt:217)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:373)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:192)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:150)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:302)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:417)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:428)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:332)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.inflate(LayoutInflater.java:663)
at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:361)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:727)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$7(RenderTask.java:883)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Both of modules has a equal compose dependencies and settings in build.gradle files:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.2.0-alpha03'
}
And:
dependencies {
...
implementation "androidx.compose.ui:ui:1.2.0-alpha03"
implementation "androidx.compose.ui:ui-tooling:1.2.0-alpha03"
implementation "androidx.compose.ui:ui-tooling-preview:1.2.0-alpha03"
implementation "androidx.compose.foundation:foundation:1.2.0-alpha03"
implementation "androidx.compose.foundation:foundation-layout:1.2.0-alpha03"
implementation "androidx.compose.material:material:1.2.0-alpha03"
implementation "androidx.compose.material:material-icons-core:1.2.0-alpha03"
implementation "androidx.compose.material:material-icons-extended:1.2.0-alpha03"
implementation "androidx.compose.animation:animation:1.2.0-alpha03"
implementation "androidx.compose.animation:animation-core:1.2.0-alpha03"
implementation "androidx.compose.animation:animation-graphics:1.2.0-alpha03"
implementation "androidx.compose.runtime:runtime-livedata:1.2.0-alpha03"
implementation "androidx.compose.compiler:compiler:1.2.0-alpha03"
...
Why I can't see previews in othergames module? How to solve it?
I found a solution to fix it. In module where previews broke I added library which I removed recently:
implementation 'androidx.appcompat:appcompat:1.4.1'
Once I did it, previews appeared again. I not sure this library is real reason, because core module doesn't contains this library, but still show preview.
UPDATE:
Time passed and I ran into this problem again. Now it is not solved by adding the library I mentioned above. I still don't know what to do.
Came across the exact issue earlier. Make sure everything is up to date, this includes:
Android Studio ( Help > Check for updates)
Jetpack Compose (project level build)
Kotlin (project level build)
Other than that, the compose-tooling dependency should have the same version as that of Compose itself.
Here's what solved my issue
#Preview(showSystemUi = true, showBackground = true) // Apparently, adding these two lines seems to do the magic here
#Composable
fun MyComposable(){
...
}
Well, that should be pretty much it.
Have a look at Studio BumbleBee "Render Problem" For Compose Preview
Whenever you see a "try to build the project" error, always check the gradle implementations first.
Then, move on to whether your version numbers are correct.
Alpha versions aren't always the best choices.
So, if you can't find an error in the implementations, roll back any error associated implementation to it's previous stable release.
Then check again.
Also, maybe try and create a new android studio project and check if the core implementations in both the new and your current are similar or, at least look ok for the common ones.
If they look ok, add a comment besides all the implementations that look ok. Then focus on the other implementations.
Now, assuming your error is the same, i.e. a combination of try to build the project and is associated with compose, check all your ui based implementations and, your jetpack compose implementations if you are using those. Hope it helps.

'A newer version of com.facebook.android:facebook-android-sdk than [5,6) is available: 4.34.0 '

According to the Facebook documentation, I have to add the following line in my Gradle file:
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
But I get the error:
A newer version of com.facebook.android:facebook-android-sdk than [5,6) is available: 4.34.0
If I set the version to 4.34.0 it seems that I don't have the latest version as I have some warnings mentioning that some methods are deprecated.
Why do I get this error message ? Should I really use [5,6) and not 4.34.0 ? By the way, what does [5,6) mean ?
Thanks !
Use the latest version
implementation 'com.facebook.android:facebook-android-sdk:7.1.0'
In my Android studio it suggesting to use version 5.15.3

Huawei devices: The meta-data tag in your app's AndroidManifest.xml does not have the right value

I'm working in a massive use app that has been working for about 4 years, in the last release was implemented some new libraries, after that implementation we have facing some issues when trying to check if Google Play Services are available, this only happens on Huawei devices with Android 8+. The logcat show us this stack trace
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 12451000 but found 4323000.  You must have the following declaration within the element:     
We have the correct values on manifest:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="XXXXXXXXXXXXXXXXXXXXXX" />
If we follow the value of google_play_services_version, we can found the expected value from play-services-basement-16.1.0.aar
<integer name="google_play_services_version">12451000</integer>
This are the libs implemented on gradle
implementation "com.android.support.constraint:constraint-layout:$constraint"
implementation "com.android.support:appcompat-v7:$support"
implementation "com.android.support:design:$support"
implementation "com.android.support:cardview-v7:$support"
implementation "com.android.support:recyclerview-v7:$support"
implementation "com.android.support:design:$support"
implementation "com.android.support:support-v4:$support"
implementation "com.android.support:mediarouter-v7:$support" //New Lib
implementation "com.android.support:animated-vector-drawable:$support" //New Lib
implementation "com.android.support:design:$support"
implementation "com.android.support:support-vector-drawable:$support"
//Play services
implementation "com.google.android.gms:play-services-maps:$playServices"
implementation "com.google.android.gms:play-services-analytics:$playServices"
implementation "com.google.android.gms:play-services-gcm:$playServices"
implementation "com.google.android.gms:play-services-safetynet:$playServices"
implementation "com.google.android.gms:play-services-wearable:$playServices"
With this versions
ext {
//build
sdkCompileVersion = 27
sdkMinVersion = 16
sdkTargetVersion = 27
sdkBuildToolsVersion = '27.0.3'
//dependencies
support = '27.1.0'
playServices = '16.0.0'
newRelic = '5.18.0'
constraint = '1.1.2'
}
Does anyone have an idea how to solve this issue?
Did you hardcode value of gms version anywhere in your application? Something like this
applicationInfo.metaData.putInt("com.google.android.gms.version", 4323000);
It is also possible that one of the new libraries that you added also declares an older/different com.google.android.gms.version.
If it is happening on Huawei only, then it’s possible that Huawei is attempting to override with some value.
To confirm whether it’s your own libraries or Huawei, you will have to hardcode it into the manifest, then analyze your built apk and inspect the final value that’s merged in there. If that value is as expected, then it’s probably Huawei’s doing.
You can also try this link:
https://stackoverflow.com/a/52249677/6668797
If a library is using an old/different version, then this will override it with yours.
If it is still not resolve the issue, can you please provide the following details:
Please share the complete stack trace.
Is it happening on any Nexus/Pixel devices?
Which of those libraries are newly added?

AdvertisingIdClient: Error while reading from SharedPreferences java.lang.SecurityException: MODE_WORLD_READABLE no longer supported

I want to integrate adjust SDK on my project but I got this error
AdvertisingIdClient: Error while reading from SharedPreferences java.lang.SecurityException: MODE_WORLD_READABLE no longer supported
but I didn't use MODE_WORLD_READABLE anywhere
here my code
String appToken = getString(R.string.adjust_token);
String environment = AdjustConfig.ENVIRONMENT_PRODUCTION;
AdjustConfig config = new AdjustConfig(this, appToken, environment);
config.setLogLevel(LogLevel.VERBOSE);
Adjust.onCreate(config);
registerActivityLifecycleCallbacks(new AdjustLifecycleCallbacks());
here my gradle
compile 'com.adjust.sdk:adjust-android:4.14.0'
compile 'com.android.installreferrer:installreferrer:1.0'
I was also facing the same issue in android API 28. I had to update 'com.google.android.gms:play-services' in app\build.gradle file and 'com.google.gms:google-services' in project gradle file with latest releases. Hope it helps.
Reason you are seeing this warning is probably because you are using older version of Google Play Services dependency in your app. Which version are you using? Give latest version a shot:
implementation 'com.google.android.gms:play-services-analytics:16.0.5'

Room annotation processor with Data binding

I have used Data binding in my existing code and now I am migrating to Room for persistence.
I have followed the steps mentioned in Florina's Blog for room
My Code builds fine without java code error or BR related error when I remove room dependency
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
and its runs too, but gives Runtime exception saying database_Impl does not exists. As it couldn't generate that's file.
But after I put Annotation processor back, it give me
Error:(29, 37) error: cannot find symbol class BR
My gradle plugin used is com.android.tools.build:gradle:3.0.1
They both don't seem to work together
Steps taken so far:
Changed BaseObservable to Observable As suggested here
Updated Android Studio to 3.0.1
Tried using gradle latest plugin canary 6
Clear, Clear Cache also done
Has anyone used Room and Data binding together ?
After 4 days of efforts I finally made my code run properly.
Steps to solve the
Data binding error like
error: package com.packagename.databinding does not exist
error: cannot find symbol class CustomMainActivityBinding
The app gradle must have below code added in order to view more than 100 errors that come by default
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "4000"
options.compilerArgs << "-Xmaxwarns" << "4000"
}
}
}
Gradle dependencies for data binding and Room arch components
annotationProcessor 'com.android.databinding:compiler:3.0.1'
implementation 'android.arch.lifecycle:extensions:1.0.0'
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
Note: Gradle plugin version is 3.0.1
I changed my all VMs to implement Observable and call
registry.notifyChange(this, BR.bar);
in case of notify change and also implement overridden methods
#Override
public void addOnPropertyChangedCallback(OnPropertyChangedCallback
callback) {
registry.add(callback);
}
#Override
public void removeOnPropertyChangedCallback(
OnPropertyChangedCallback callback) {
registry.remove(callback);
}
These things made my code Build, but it run without exceptions when I solved the Room query related errors. Which was the main reason, code was building but not running. These errors I could see when I Rebuid my project again.
UPDATE:
After Android studio 3.1.3, Message window is gone and now all build error appears under Build view. Although there is toggle available to get textview response of error, for data-binding errors it isn't sufficient.
Solution that helped me:
In Command promt/Terminal navigate to project root.
Run this command "./gradlew build --stacktrace" if Mac or ".\gradlew
build --stacktrace" if Windows.
Now search for "error:" tag and the compile time errors will show up.
I couldn't get these errors in IDE.
In my experience, the following reasons may cause the error:
Incorrect getter/setter (missing or incorrect name)
Incorrect return type in Dao
annotationProcessor or kapt issues
The default constructor is overridden (you need to keep the empty constructor for Room)
I faced this issue while adding room dependencies. Add this in the below way to resolve the error.
def roomVersion = "2.0.0-rc01"
implementation "android.arch.persistence.room:runtime:$roomVersion"
annotationProcessor "android.arch.persistence.room:runtime:$roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$roomVersion"

Categories

Resources