Error trying to render MaterialButton from Material Components - android

I followed the getting started guide here, I don't want to migrate to androidx at this time so I did:
Made sure I have the correct repositories
Added com.android.support:design:28.0.0-rc01 to my dependencies, since the Getting Started tutorial states this is the only thing needed if I don't want to migrate to androidx.
Made sure compileSdkVersion was 28
Switched to Theme.MaterialComponents.Light.NoActionBar
Downloaded Android P SDK and sources (but not any of the rest that's not on the image):
Made sure I am using AppCompactAtivity
Rebuilt the project
And I still get the error:
The following classes could not be found:
- com.google.android.material.button.MaterialButton
What am I missing?

You should not use com.google.android.material package instead use com.android.support.
In your case android.support.design.button.MaterialButton

I had that problem with Android Studio 3.2 release candidates, both using com.android.support and using com.google.android.material.
I upgraded to the 3.3 canary and that specific problem went away although I now have other (unrelated?) problems (runtime failures to inflate, etc).
I can't find any documentation stating required Android Studio versions for layout editor to work.

Make sure that the repositories section includes Google’s Maven repository google(). For example:
allprojects {
repositories {
google()
allprojects {
repositories {
google()
jcenter()
}
}
Add the library to the dependencies section:
implementation 'com.google.android.material:material:1.0.0'
dependencies {
// ...
implementation 'com.google.android.material:material:1.0.0'
// ...
}

Related

Android Studio: Unresolved reference despite Gradle sync successful after adding third party implementation. Works fine with previous version

I am trying to add this library:
https://github.com/blipinsk/ViewPropertyObjectAnimator
I have added this to my build.gradle file's dependencies:
implementation 'com.bartoszlipinski:viewpropertyobjectanimator:1.5.0'
The Gradle sync is successful after this too.
However when I try to use it:
ViewPropertyObjectAnimator.animate(this#CustomToolbar).topMargin(it).setDuration(200).start()
It keeps telling me Unresolved reference: ViewPropertyObjectAnimator. And I am unable to import as the com.bartoszlipinski doesn't exist when importing.
If I change the library version from 1.5.0 to 1.4.5:
implementation 'com.bartoszlipinski:viewpropertyobjectanimator:1.4.5'
it works fine and import works fine too.
I would prefer using the newer version instead of the old one. Where am I going wrong?
EDIT: I just noticed that even though Gradle sync is successful, it logs a warning:
Failed to resolve: com.bartoszlipinski:viewpropertyobjectanimator:1.5.0 Show in Project Structure dialog Affected Modules: app
And with the older version, I can see the library in the Android Studio's "External Libraries" but it's not there in the newer library version:
Edit 2: I think I figured it out. I came across this:
https://github.com/blipinsk/ViewPropertyObjectAnimator/issues/16
Using custom bintray repo is a bit unusual, and mavenCentral only has up to 1.4.5. Any chance of updating to 1.5.0 on mavenCentral too? Just curious, but technically bintray works well for me atm too
So it seems like mavenCentral doesn't have the updated version.
I recently came across this issue, I added jitpack repository to the settings.gradle file instead of the root file.
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url "https://jitpack.io" }
}
}
Implementation in the build.gradle file was the same.
implementation 'com.github.blipinsk:ViewPropertyObjectAnimator:1.5.0'
I was able to figure this out. I came across this:
https://github.com/blipinsk/ViewPropertyObjectAnimator/issues/16
Using custom bintray repo is a bit unusual, and mavenCentral only has up to 1.4.5. Any chance of updating to 1.5.0 on mavenCentral too? Just curious, but technically bintray works well for me atm too
So it seems like mavenCentral doesn't have the updated version. As a workaround, I added
maven { url "https://jitpack.io" }
to
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
and then change the dependency to:
implementation 'com.github.blipinsk:ViewPropertyObjectAnimator:1.5.0'

How to run "Watchface for wearos" codelab?

I am new to Android and WearOS and also to Gradle, and I just want to follow along this Codelab:
https://codelabs.developers.google.com/codelabs/watchface/index.html#0
So I downloaded Android Studio and imported the project
https://github.com/googlecodelabs/watchface
but when compiling I just get the error
Failed to resolve: com.google.android.support:wearable:2.0.0
I already tried to change SDK Versions and other things, but it didn't help.
I'm pretty sure it's just a few version settings, but I have no idea where to look.
Did anyone maybe complete this codelab and made it run with the "actual" version of AndroidStudio?
thanks,
Thorsten
The code on github was last updated in May 2017, which is a shame, as it is a useful introduction to watchfaces. A number of things have changed since then. There is even a pull request on github with gradle updates from Nov 2018, but it hasn't been merged.
Your 'Failed to resolve' error is likely related to Google now providing some packages in their own Maven repository, in addition to jcenter.
This can be fixed by adding google() to the repositories closures in the Package build.gradle file:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
The version of the gradle plugin has been changed to 4.0.2 above too, so also update the file gradle-wrapper.properties with:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Gradle should now build, but it may still log some warnings or errors in the Build window which you can open at the bottom of Android Studio.
The gradle dependency keyword 'provided' has been replaced with 'compileOnly' and 'compile' with 'implementation'. Shift+Ctrl+R in Android Studio will enable you to easily do the replacement project-wide.
It should also be useful for updating compileSdkVersion and targetSdkVersion (to 30) and buildToolsVersion (to 30.0.2) in all the module build.gradle files.
The package versions are out of date, with the wearable ones currently at 2.8.1 and play-services-wearable at 17.0.0. Ctrl+Alt+Shift+S takes you to 'Suggestions' in 'Project Structure', which can help you in future to stay current.
The last problem is that the Android Support Library has been obsoleted in favor of jetpack/androidx. See the old reference.
In this project, it is only a problem in the build.gradle of module 5-palette. You may replace 'com.android.support:palette-v7:23.3.0' with 'androidx.palette:palette:1.0.0'. See Jetpack Artifact Mappings. You then need to change the import statement in MyWatchFaceService.java.
Finally add the following line to gradle.properties:
android.useAndroidX=true

How to implement implementations in android without error?

I want to add AdView to my activity and I click on download and then it automatically implements the necessary library. But then I get the following error:
Error 1
I get the same error when I try to add GridLayout to my library.
Here is my gradle file: gradle file
I already tried to set the Global Gradle settings to offline work but it doesn't help.
I have android studio 3.4.2
This is a problem that bothers me for a while now and there seems no solution to this. Is it possible that these things are not available for androidx yet? Thank you for your help!
From the documentation:
To make the Google Play services APIs available to your app:
Open the build.gradle file inside your application module directory.
Note: Android Studio projects contain a top-level build.gradle file and a build.gradle file for each module. Be sure to edit the file for your application module. See Building Your Project with Gradle for more information about Gradle.
Add a new build rule under dependencies for the latest version of play-services, using one of the APIs listed below.
Ensure that your top-level build.gradle contains a reference to the google() repo or to maven { url "https://maven.google.com" }.
Save the changes, and click Sync Project with Gradle Files in the toolbar.
You can now begin developing features with the Google Play services APIs.
This is often a common mistake. If you have multiple repositories in your gradle, make sure that maven google is at the top of the list.
eg.
repositories {
maven { url "https://maven.google.com" }
...
}
This package:
// https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads
implementation "com.google.android.gms:play-services-ads:18.1.1"
is either available from repository google() or from repository mavenCentral():
repositories {
google()
mavenCentral()
...
}
see the quick-start.

Where to put JAXB dependency for compiling Android Databinding on Java 11?

I am using Android Data Binding, and while things were simple it was working very well. However, once I added a BindingAdapter annotation, my project stopped building in Android Studio with an error Execution failed for task ':app:compileSaferesourceDebugJavaWithJavac', but it didn't give me any more detail. Running gradlew build on the command line showed that the actual error was java.lang.ClassNotFoundException: javax.xml.bind.JAXBException. This makes sense, because this development machine has only Java 11 installed, not Java 8.
I found this answer, which says to add the following dependencies to gradle:
implementation "javax.xml.bind:jaxb-api:2.2.11"
implementation "com.sun.xml.bind:jaxb-core:2.2.11"
implementation "com.sun.xml.bind:jaxb-impl:2.2.11"
implementation "javax.activation:activation:1.1.1"
The problem I have is that I don't know where to add them. Adding them as implementation dependencies to the app/build.gradle doesn't work, because JAXB is a dependency of the build tools, not of my application itself.
I tried adding them as buildscript.dependencies too, but that didn't work either:
buildscript {
repositories {
google()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "javax.xml.bind:jaxb-api:2.3.1"
classpath "com.sun.xml.bind:jaxb-core:2.3.0"
classpath "com.sun.xml.bind:jaxb-impl:2.3.1"
classpath "javax.activation:activation:1.1.1"
}
}
I also tried adding them as buildscript.dependencies in the project root build.gradle file, but that also did not help:
buildscript {
repositories {
google()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "javax.xml.bind:jaxb-api:2.3.1"
classpath "com.sun.xml.bind:jaxb-core:2.3.0"
classpath "com.sun.xml.bind:jaxb-impl:2.3.1"
classpath "javax.activation:activation:1.1.1"
}
}
I know that I can use Java 8 to build this code, but I really don't want to have to deal with multiple Java versions and I have other projects that require Java 11.
Is there a place in the gradle configuration that I can put these build dependencies to get them to work?
Configurations I tested:
Operating Systems: Tested on Windows 10 and Windows Server 2016
Build Environments: Tested in Android Studio 3.4.1, Android Studio 3.5.0-beta04, and using Gradle Wrapper on the command line
Android Gradle Plugin: tested with 3.4.1 and 3.5.0-beta04
Android Build Tools: tested with 28.0.3 and 29.0.0
Note: comment asks for Databinding version, which is no longer relevant since Databinding is now built-in and does not have a separate version number.
Fail with error show above:
Java 11.0.1 x64
Working properly:
Java 1.8.0_212 x64
After extensive testing, it is clear that the Java version is the only thing that makes any difference here.
UPDATE As of 2020-07-21, the Android bug tracker now states:
Studio will also start using JDK 11 starting in 4.2, approx in 1 to 2 months.
According to a member of the Android Project on the Android Bug Tracker as of 2019-03-07:
Java 11 is not supported by Android studio and its tools.

Android Firebase not Implementing Properly

In my Project build.gradle i added these lines
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.1.1'
...
}
}
allprojects {
repositories {
...
maven {
url "https://maven.google.com"
}
...
}
}
and in my app build.gradle
dependencies {
//firebase
implementation 'com.google.firebase:firebase-ads:11.8.0'
...
}
apply plugin: 'com.google.gms.google-services'
every thing is fine, gradle sync without warning or any errors, but am not able to use any of the firebase-ads library classes i can't find them it's like i never added that dependency even i manually types com.google.android.gms. and there is no package called ads
even in .xml files i added an AdView when i press Ctrl and hover over the class name, all packages get highlighted untill gms, the ads and adView dosen't get highlighted.
i restarted Android studio,invalidate the cache, sync gradle with and without firebase-ads dependency, removed the library cache from .gradle file, nothing worked.... am i missing something?
You should also add implementation 'com.google.firebase:firebase-core:11.8.0' as a dependency. This is Firebase core dependency and should be added always.
I would recommend you to use the option from Android Studio: Tools->Firebase and then you can choose the tool you want.
the solution was to use an older version of firebase libraries '9.0.2' and it worked, thats still wierd i still want to know the real reason and if it was a bug in the libraries or Android studio to send a bug report

Categories

Resources