Android Studio - Create new project with errors? - android

I create a new android studio project over the wizard and choose Empty Activity (checked backward compatibility too). After the project is created, I got this two errors:
What is wrong? I don´t change any line code and I don´t find any solution for this.
I use the current version of android studio (checked updates a minute ago):
Android Studio 3.1.3
Build #AI-173.4819257, built on June 4, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 8.1 6.3
Thanks!

You may want to confirm these details
compileSdkVersion 27
targetSdkVersion 27
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
Clean and Rebuild Project

Make sure you have the correct imports. Try:
import de.kampis_elektroecke.dogsvscats.R;

Try this.Goto: src -> main -> res -> style.xml and add Base. to the style tag parent attribute.
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
...
</style>
If that doesn't work, see this post:Theme.AppCompat.Light resource not found in Android Studio

Related

Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'

I'm having a problem with running my android app:
Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'
That is caused by 1.7.0:
implementation 'com.google.android.material:material:1.7.0'
You better stick to 1.6.0 till they fix this
implementation 'com.google.android.material:material:1.6.0'
In your build.gradle file where "dependencies" section is paste this:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
in this section. And remove old strings with same text and other number versions. (in my case:
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
). Have worked for me.
source: https://github.com/facebook/react-native/issues/33926
Upgraded android gradle plugin to 7.2.2 and the problem is solved. Try updating Android Studio too
Rationale
To expand on the existing answers, the release notes for Material Components for Android 1.7.0 mentions that they have updated the minimum requirements for your project (emphasis mine):
New minimum requirements for your app's project:
Update to Android Gradle Plugin (AGP) version 7.2.0
Update to Gradle version 7.3.3
Update to Java 8 (version 1.8)
Update to Android Studio Chipmunk, version 2021.2.1
This is also mentioned in their (updated) Getting Started guide (again, emphasis mine):
5. Gradle, AGP, and Android Studio
When using MDC-Android version 1.7.0-alpha02 and above, you will need to make sure your project is built with the following minimum requirements, in order to support the latest build features such as XML macro:
Gradle version 7.3.3
Android Gradle Plugin (AGP) version 7.2.0
Android Studio Chipmunk, version 2021.2.1
Updating the Android Gradle Plugin
You can update the Android Gradle plugin as follows:
Gradle plugins DSL
The plugin declaration can be found in the top-level build.gradle/build.gradle.kts file:
plugins {
// Or "com.android.library"
id("com.android.application") version "7.2.2" apply false
}
Buildscript classpath
Update the AGP classpath dependency (usually in the top-level build.gradle/build.gradle.kts file):
classpath("com.android.tools.build:gradle:7.2.2")
update your build.gradle file as below:
classpath 'com.android.tools.build:gradle:7.2.1'
It will fix the issues, remember v7.3.x wont fix the issue, so stick to 7.2.1 as of now.
For Flutter User with this issue this is how you solve it::
Goto : build.gradle
change "classpath 'com.andriod.tools.build:gradle:5.6.0'"
to
"classpath 'com.andriod.tools.build:gradle:<latest version>'"
in my case :: classpath 'com.android.tools.build:gradle:7.2.1'
then goto :: android/gradle/wrapper/gradle-wrapper.properties
then change
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.3-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-<latest>-all.zip
in my case distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
In build.gradle(:app),
Updating, compileSdk and targetSdk to 33 helped me(from 32).
In order to get over with this. Upgrade to the latest gradle version as well as latest Android Studio.
I was also facing this issue and I followed these steps :
Upgraded Android Studio to Android Studio Dolphin | 2021.3.1 Patch 1
gradle version to 7.3.1 in project build.gradle
kotlin version to 1.7.20 in project build.gradle
targetSdkVersion and compileSdkVersion to 33
latest version of dependencies in app's build.gradle
And the project is perfectly working fine now.
I resolved it by replacing implementation 'androidx.recyclerview:recyclerview:1.2.1' instead of implementation 'com.google.android.material:material:1.7.0' in build.gradle(:app)
Upgraded android gradle plugin >= 7.1.0 and the problem is solved.
classpath "com.android.tools.build:gradle:7.1.0"
After wasting 2 hours and ruining my mood solution was simply upgrading your android studio version, most probably you are using an older version like Arctic fox or something like that, upgrade to dolphin or something higher. Hope it help, and yes in dolphin version it will give error of 30.0.3 but don't worry it gives you an attached link to install 30.0.0 SDK in console itself, so chill and keep developing.
first, in the gradle build file, change the implementation from 1.7.0 to 1.6.0
Next, open the colors file and change the color of the tag (#) which has 7 digits to a 6 digit tag. Because usually the default color of tags on Android Studio is sometimes 7 digits or 6 digits
I solved this by :
Adding in build.gradle:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
adding android:exported="true" in Manifest

build failed Google io 2018 (iosched)

Download the project of Google IO 2018 (iosched), try to compile it in Android Studio 3.3 Canary 7, also the probe in 3.2 RC1. But I get the following error:
error: resource style/TextAppearance.MaterialComponents.BottomNavigationView.Colored (aka com.google.samples.apps.iosched:style/TextAppearance.MaterialComponents.BottomNavigationView.Colored) not found.
Checking the file style. xml, it is observed that fails to find the style TextAppearance.MaterialComponents.BottomNavigationView.Colored.
<style name="TextAppearance.IOSched.BottomNavigationView" parent="#style/TextAppearance.MaterialComponents.BottomNavigationView.Colored">
<item name="android:fontFamily">#font/google_sans</item>
<item name="android:textColor">#color/bottom_nav_item</item>
</style>
Also check that the Google Material components dependency if implemented.
implementation "com.google.android.material:material:$rootProject.materialVersion"
I can't understand why it might be making this mistake.
you can see here
https://github.com/google/iosched/issues/285#issuecomment-416114763
you can use the Android Studio Stable 3.2
use the last dependencies.
in the file iosched/gradle.properties,mofiy
androidGradlePluginVersion = '3.2.0'
materialVersion = '1.0.0'
kotlinVersion = '1.2.51'
in the file iosched/mobile/src/main/res/values/styles.xml
change
#style/TextAppearance.MaterialComponents.BottomNavigationView.Colored
to
#style/Widget.MaterialComponents.BottomNavigationView.Colored
I have managed to make it compile by installing android studio 3.2.0 beta 4.
as seen in the following image
with Android Studio 3.1.4 it builds, unless updating the outdated dependencies. there also is on open issue: https://github.com/google/iosched/issues/285
and it does complain much when building with ./gradlew build
once I've manually updated those beta01 versions to rc01 I also get that:
error: resource style/TextAppearance.MaterialComponents.BottomNavigationView.Colored (aka com.google.samples.apps.iosched:style/TextAppearance.MaterialComponents.BottomNavigationView.Colored) not found.
which basically means, that material-components-android is missing or outdated. to resolve this, you could simply copy the absent style from GitHub and manually add it into styles.xml or simply do not update that outdated library versions, until there is a final release of all those release candidates, which are not yet considered as "stable".
the bottom line may be, that it builds against materialVersion = '1.0.0-beta01' (which might contain that style), but not against materialVersion = '1.0.0-rc01' (which may lack that style).
maybe consider using a stable version of Android Studio, alike 3.1.4 - instead of using the canary channel and then complain it won't work; maybe you even build unknowingly against the rc01 version, because this is exactly the issue which I get when updating that library to rc01 - and the title of this question also boldly states RC01.

Android Studio Gradle adding Gson: Unresolved Reference / Please select Android SDK

I add Gson to my gradle dependencies and nearly all dependencies stop to resolve. (additionally I get the "Error: Please select Android SDK"-Error)
I know this a well known bug and I can solve it as described in this post.
I took like 3 tries with different versions, but i just not works.
Android Studio: "Please select Android SDK"
Any hints why Gson makes here trouble?
(I'm using Kotlin.)
My Android Studio:
> Android Studio 3.1.2 Build #AI-173.4720617, built on April 13, 2018
> JRE: 1.8.0_152-release-1024-b02 amd64 JVM: OpenJDK 64-Bit Server VM by
> JetBrains s.r.o Windows 10 10.0
Relevant gradle.build snippet
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4'
// -erro- implementation 'com.google.code.gson:gson:2.8.2'
implementation "com.google.code.gson:gson:+"
It's not recommended to use the latest version (+), use this instead:
implementation 'com.google.code.gson:gson:2.8.5'

Kotlin javaClass<> missing dependency in latest Android Studio 3.0

Toolchain:
Android Studio 3.0 Canary 2:
Build #AI-171.4041253, built on May 24, 2017
JRE: 1.8.0_112-release-b736 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.5
Google SDK/Tools: I have downloaded the latest "all" (Android O, tools, libraries, etc. at least according to Android Studio SDK Manager).
Problem: javaClass<> is missing and Android Studio can't "import it".
What I did:
Create new Android project, target API 23 and told it to include a "basic activity".
Added the Gradle dependencies for ViewModel and Room taken from: https://developer.android.com/topic/libraries/architecture/adding-components.html
These are the lines I added to my App Module's gradle file:
compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
The Kotlin reference in the same Gradle is: compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" (I didn't add that one, came automatically)
I then created a simple Kotlin class called MainViewModel:
import android.arch.lifecycle.ViewModel
class MainViewModel : ViewModel() {}
Then I went to my Activity and tried to do what this Google Documentation says: https://developer.android.com/topic/libraries/architecture/viewmodel.html
It's in Java but converted to Kotlin, I think it should look like:
val mainViewModel = ViewModelProviders.of(this).get(javaClass<MainViewModel>)
The problem is that Android Studio is not finding javaClass and the fix (to press ⌥⏎) doesn’t do anything.
What am I missing?
I decided to try to use the Java To Kotlin conversion. So I created a new Activity in Java, and wrote the above code as the java documentation states.
After the class was working, I did Code -> Convert Java Class To Kotlin in Android Studio, and the resulting Kotlin class had the following line:
val viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
This compiled perfectly. I will have to learn more about which one is correct, but this one may save you some time if you’re, like me, new to the language.

Android Studio problems since the last update to 0.8 version

I'm following the Google I/O conference and just a week before they announced that Android Studio 0.8 is available for downloading. Before that I used 0.6 and I was developing an application. Now I'm having both 0.6 and 0.8 on my Ubuntu. I added all the update from SDK for Android Watch and TV and all the Material Design stuffs. And today when I opened my project in the 0.8 version, after a few updates of some things, I'm receiving an error
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version L declared in library com.android.support:appcompat-v7:21.0.0-rc1
If someone has any idea what is this all about - share please. I tried to pull my project from my repository in GitHub, but without any result. Thank you.
It looks like you have declared a dependency on version 21 of appcompat-v7 in your build.gradle.
At this time, the preview of the Android L support libraries only works with apps that declare the L preview as their min SDK.
Either revert to a previous version of the support library (I believe the latest is com.android.support:appcompat-v7:19.1.0) or update your project to support a minimum of 'L'.
just try this:
android {
android {
compileSdkVersion 20 //or whatever you want
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 14 //or whatever you want
targetSdkVersion 20 //or whatever you want
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
}
}
and if you have another module in your project, check manifest files in those modules too.
I had a similar issue like that before. After I updated to 0.8.1, it showed an error below when compiling my previous projects.
"uses-sdk:minSdkVersion 8 cannot be smaller than version L declared in library com.android.support:appcompat-v7:21.0.0-rc1".
This is how I fixed it.
In your project, find build.gradle file in app folder and open it.
At dependencies section, change the value of compile 'com.android.support:appcompat-v7'. For example, in my case, it was compile 'com.android.support:appcompat-v7:+', and I changed it to compile 'com.android.support:appcompat-v7:20.+'. Of course, you could change it to compile 'com.android.support:appcompat-v7:19.+' if you like.
I hope it would help. Let me know if you are still stuck on it.
I had similar problems. Although I'm not sure exactly what caused the problem or which step fixed the issue, I did the following and ultimately got things working again:
I closed down Android Studio
I ran SDK Manager and and checked that everything was up to date. I have the following installed:
Android SDK tools Rev. 23
Android SDK Platform-tools Rev. 20
Android SDK Build-tools Rev. 20
Android L (API 20, L preview)
Android 4.4W (API 20)
Android 4.4.2 (API 19)
I restarted Android Studio and started a new (blank) project to test and ran it -> Success!
I found the process pretty finickity, so your mileage might vary. Let me know how you go.
I had the same error. I found the solution.
dependencies {
compile ('com.android.support:support-v13:20.0.0'){
force = true
}
compile ('com.android.support:support-v4:20.0.0'){
force = true
}
compile ('com.android.support:appcompat-v7:20.0.0'){
force = true
}
}
I think that instead of 20.0.0, you can specify a different version if you use less than 20 targetSdkVersion.
I had the same issue.
I made the following changes to the dependencies section in build.grade file located in the app folder.
'com.android.support:appcompat-v7:20.0.0' to 'com.android.support:appcompat-v7:20.+'

Categories

Resources