resource android:style/TextAppearance.Material not found - java

I am trying to write a Hello World program for android. This is my first experience of Java. Gradle is not running properly, and whenever I try to rerun it, it comes up with 24 error messages:
resource android:style/TextAppearance.Material not found
and then lots of attributes of android:style/TextAppearance.Material which are also not found. I have tried searching online for how to put something in styles.xml to fix this, but can't find anything useful.

Try to change you theme to an Android Support Library's material design theme.
Don't forget to include the Support Library as well.
Manifest:
<application android:theme="#style/Theme.AppCompat">
Gradle Build file:
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.0'
}
I would also recommend to you that you read the Styles and Themes documentation. https://developer.android.com/guide/topics/ui/look-and-feel/themes.html

In my case the problem was this:
configurations {
compile.exclude group: 'androidx.annotation', module: 'annotation'
compile.exclude group: 'androidx.core', module: 'core'
}
had to comment this block out and it worked.

Related

How do I fix this "Duplicate class error" in Android Studio

I updated implementation com.google.android.gms:play-services-ads:19.8.0 to implementation com.google.android.gms:play-services-ads:20.4.0 and now I get this error:
Duplicate class com.google.android.gms.internal.measurement.zzbs found in modules jetified-play-services-measurement-18.0.2-runtime (com.google.android.gms:play-services-measurement:18.0.2) and jetified-play-services-measurement-sdk-api-18.0.3-runtime (com.google.android.gms:play-services-measurement-sdk-api:18.0.3)
Duplicate class com.google.android.gms.internal.measurement.zzl found in modules jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2) and jetified-play-services-measurement-sdk-api-18.0.3-runtime (com.google.android.gms:play-services-measurement-sdk-api:18.0.3)
Duplicate class com.google.android.gms.measurement.internal.zzfh found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgn found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgo found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgp found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgq found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzhs found in modules jetified-play-services-measurement-18.0.2-runtime (com.google.android.gms:play-services-measurement:18.0.2) and jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3)
Duplicate class com.google.android.gms.measurement.internal.zzhx found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
How to fix this error?
I ran into the same issue today, and after many trial and errors, I finally found that it was caused by a firebase dependency. If you're using firebase in your project, make sure to use the latest BoM version in app/build.gradle:
dependencies{
// implementation platform('com.google.firebase:firebase-bom:25.12.0') <-- Produces errors
implementation platform('com.google.firebase:firebase-bom:29.0.0') //<-- This works
}
If you are not using firebase and still get this error, you can try excluding the offending classes directly in app/build.gradle:
android {
defaultConfig {
...
}
buildTypes {
...
}
configurations {
all {
exclude group: "com.google.android.gms", module: "play-services-measurement-impl"
exclude group: "com.google.android.gms", module: "play-services-measurement"
}
}
}
I am having the same issue and I fixed it by downgrading play-services-ads dependency like this. So you can try.
def ads_version = "20.3.0"
implementation "com.google.android.gms:play-services-ads:$ads_version"
The error is being produced due to the conflicts between firebase & google service dependency. So you have 2 options.
You can change the versions and keep doing that until you find the perfect working combination which is time consuming or you can find a solution that works every time so you don't have to play with the versions every time. You just use that solution wherever you get such error.
Here, you need to use the updated method of injecting the firebase dependency as shown in the official documentation.
Put this line in your dependency :
implementation platform('com.google.firebase:firebase-bom:28.1.0')
Then, You can use any firebase dependency without specifying the versions, and it will work flawlessly all the time!
The final code looks like this,
implementation platform('com.google.firebase:firebase-bom:28.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-config'
implementation 'com.google.firebase:firebase-crashlytics'
And it won't produce any duplication related errors with the play-services dependency.
Best way to fix this and prepare your project for later is to migrate completely to AndroidX. First check if your project is ready, Refactor > Migrate to AndroidX. Once your project is independent of jcenter or any other older library/repo and compatible with AndroidX you won't need Jetifier anymore, so either comment it out or remove it. This should possibly fix the problem.
...
#android.enableJetifier=false
...
In my case this wasn't enough to solve the problem, if you still receive the same error but from a different library, it's possibly because of other existing dependencies, avoid using bundled libraries or wildcard ones (in which system is left to guess) make sure you update them all and clean rebuild the project.
If you still have to keep some conflicting library, try excluding individual classes to avoid the error like this from build.gradle:
android {
...
defaultConfig {
...
}
buildTypes {
...
}
configurations {
all { // You should exclude one of them not both of them
exclude group: "com.android.support", module: "support-core-ui"
exclude group: "com.android.support", module: "support-compat"
}
}
}
Official docs on module exclusion - Excluding transitive dependencies
I also tried few more things before figuring the solution, like deleting .gradle from local machine, incase some old libraries got cached and causing the error, or resetting Android Studio, it just won't work.
Repo I tested the solution here, as you can see in this line I had to comment out the bundle module and specify latest updates to individual dependencies.
You can read more on module dependency errors for reference.
Add this line android.enableJetifier=true to your gradle.properties

Using your own Java library in another project?

So despite developing with Java for quite a while, I've only just decided to give making my own library a go. I've created it, and have a second project within Intellij Idea, but I don't know how to use said library in the second project. This is what I have so far:
In my library, build.gradle is:
apply plugin: 'java-library'
version = '0.0.1'
repositories {
jcenter()
}
jar {
manifest {
attributes(
'Implementation-Title': project.name,
'Implementation-Version': project.title
)
}
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.12'
}
I guess what my question is, is how do I implement my library into the second project so that I can use it (and test it properly) in the second project? I've tried to search the net to find the answer to this and cannot seem to get an explanation that makes sense to me.
I have a multi-project in the same window of Intellij Idea.
I find the official guide very meaningful about how to build a custom library.You can follow that way : Building Java Libraries.
To look for the testing part with JUnit, you can follow that rules.

Android Studio 3.0 - "Failed to transform file 'gson-2.2.4.jar' to match attributes {artifactType=android-classes}"

I'm a newcomer to Android Studio development, and I'm currently following an online tutorial to make a messenger app.
I've followed the steps of this tutorial, and it now needs me to download the Library files for Smack API & GSON, and add the .jar files to the libs folder in my project.
With this done, I right-clicked the files in the directory and clicked Add as library (the tutorial says to do Build Path -> Add to Build Path, but this doesn't seem to be an option in this version of Android Studio).
At this point, the project directory menu sidebar looks like this:
From here, I tried to rebuild the project but was met with the following error:
I've not been able to find a way around this error at all, and don't know enough about Android Studio to know if this is an issue with the IDE or the package itself. I've had a look around S/O but none of the posts seem to describe the same issue, or offer any solutions to similar issues that appear to work for this too.
If anyone has run into this before, or if it is a common Android Studio problem, would you be able to advise me on how to resolve it please? Very frustrating when I just want to get on with learning how to code for Android!
Any help massively appreciated, thanks in advance!
Mark
Here is best solution for importing any jar, arr libs
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
....
}
You do not need to add repeatable lines with libs file name.
if you are a new to android studio, you can check the project structure from android by tapping drop-down menu.
Since Gson is in maven central, you have to add mavenCentral() in buildscripts phase. you have to add the Gson library in the dependency using project structure, now to update the gradle, for the add the .jar file to your build.gradle file like:
dependencies {
compile files('libs/gson-2.2.4.jar')
}
or
dependencies {
compile 'com.google.code.gson:gson:2.2.+'
}
And make sure you are connected to the internet
did you try
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
in your build.graddle file of app module

Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]

I am trying to open existing android project in android studio and it gradle cannot build the app without the error
Error android studio keeps on throwing
Error:(74, 1) A problem occurred evaluating project ':app'.
> Could not find method implementation() for arguments
[com.android.support:appcompat-v7:26.0.0] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
My Code in build.gradle Which can help to understand my issue
My dependencies
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// google & support
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.android.support:recyclerview-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.android.support:palette-v7:$supportVersion"
implementation "com.android.support:customtabs:$supportVersion"
implementation "com.android.support:support-v4:$supportVersion"
implementation 'com.google.android.exoplayer:exoplayer:r2.0.4'
// utils
implementation 'com.github.bumptech.glide:glide:4.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
implementation 'com.koushikdutta.ion:ion:2.1.7'
implementation 'com.github.Commit451:bypasses:1.0.4'
implementation 'com.jakewharton:butterknife:8.8.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.0'
implementation 'com.drewnoakes:metadata-extractor:2.9.1'
implementation "com.orhanobut:hawk:2.0.1"
}
Please help to solve the issue
Make sure you're adding these dependencies in android/app/build.gradle, not android/build.gradle.
Replace compile with implementation.
compile was recently deprecated and replaced by implementation or api
Make sure your Gradle version is 3.*.* or higher before using "implementation".
Open the project level Gradle file under dependencies:
dependencies{
classpath 'com.android.tools.build:gradle:3.1.2'
}
Open the 'gradle-wrapper.properties' file and set the distributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
or latest version.
Sync the project. I Hope this solves your problem.
You need to use at least Gradle 3.4 or newer to be able to use implementation. It is not recommended to keep using the deprecated compile since this can result in slower build times. For more details see the official android developer guide:
When your module configures an implementation dependency, it's letting Gradle know that the module does not want to leak the dependency to other modules at compile time. That is, the dependency is available to other modules only at runtime.
Using this dependency configuration instead of api or compile can result in significant build time improvements because it reduces the amount of projects that the build system needs to recompile. For example, if an implementation dependency changes its API, Gradle recompiles only that dependency and the modules that directly depend on it. Most app and test modules should use this configuration.
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations
Update: compile will be removed by end of 2018, so make sure that you use only implementation now:
Warning:Configuration 'compile' is obsolete and has been replaced with
'implementation'. It will be removed at the end of 2018
change apply plugin: 'java'
to apply plugin: 'java-library'
java-library-plugin
For me I put my dependencies in the wrong spot.
buildscript {
dependencies {
//Don't put dependencies here.
}
}
dependencies {
//Put them here
}
Solved this by adding my dependancies in the app folder
Go to app < Gradle Scripts < gradle.build(Module: app) and add the depandancies in that file and not the global build.gradle file
So ridiculous, but I still wanna share my experience in case of that someone falls into the situation like me.
Please check if you changed: compileSdkVersion --> implementationSdkVersion by mistake
I moved implementation to module-level build.gradle from root-level build.gradle. It solves the issue.
Your Code
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
Replace it By
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
Replace your implementation with classpath. That should work.
As mentioned here, https://stackoverflow.com/a/50941562/2186220, use gradle plugin version 3 or higher while using 'implementation'.
Also, use the google() repository in buildscript.
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
These changes should solve the issue.
As suggested in official docs you need add these :
buildscript {
repositories {
// Gradle 4.1 and higher include support for Google's Maven repo using
// the google() method. And you need to include this repo to download
// Android Gradle plugin 3.0.0 or higher.
google()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
}
}
adding these remove my error. Also use implementation instead of compile.
In my case it was because I used Implementation instead of implementation.
For me the problem was that I wrote:
android {
compileSdk 31
…
Instead of:
android {
compileSdkVersion 31
So make sure your build.gradle is correct.
If implementation is not defined, you are writing on a wrong file. On Unity 2019+ the correct file is main template grandle and not some of the others.

UNEXPECTED TOP-LEVEL EXCEPTION while building android app

I have checked multiple times for duplicate dependencies but cannot find anything. Here are the screenshots.
Here is my build.gradle file
Here is my file structure.
Here is the error
Please help. It was running perfect since this morning.
try this and let me know
configurations.all {
exclude group: 'com.google.android', module: 'support-v4'
// other configurations
}
When I have same issue, I replaced compile with provided.
And recommendation - use concrete library that need your app like described here - http://android-developers.blogspot.com/2014/12/google-play-services-and-dex-method.html

Categories