android.view.View$OnUnhandledKeyEventListener - android

I am new to Android Studio and I don't get why my toolbar isn't shown as described by https://developer.android.com/training/appbar/setting-up
I know there are already some other questions like mine on stackoverflow but they don't work at my project. Therefore I would be very thankful for fixing this issue. Screenshot:
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:180)
at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:61)
at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:118)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:213)
at android.support.v7.widget.ViewUtils.isLayoutRtl(ViewUtils.java:58)
at android.support.v7.widget.Toolbar.onMeasure_Original(Toolbar.java:1578)
at android.support.v7.widget.Toolbar.onMeasure(Toolbar.java)
at android.view.View.measure_Original(View.java:22071)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:22035)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure_Original(View.java:22071)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:22035)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure_Original(View.java:22071)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:22035)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:590)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:343)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:544)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:678)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark">
</android.support.v7.widget.Toolbar>
build.gradle (app level)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.david.gamebase"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-auth:11.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
style.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
## toolbar.xml ##
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark">
</android.support.v7.widget.Toolbar>

If using Android X and androidx.core:core and/or androidx.appcompat:appcompat, update androidx.core:core to 1.4.0-alpha01 and/or androidx.appcompat:appcompat to 1.3.0-alpha01

Make the changes in your build.gradle (app level) to downgrade to version 27 as below. Then sync and build project. Hopefully it will fix the issue..
compileSdkVersion 27
targetSdkVersion 27
implementation 'com.android.support:appcompat-v7:27.1.1'

As mentioned by documentation, first, your Activity should be extend from AppCompatActivity().
Second, in your project styles, Base.Theme.AppCompat.Light.DarkActionBar is set which means it does have a DarkActionBar but you already have a Toolbar in your layout. So, simply, change:
Base.Theme.AppCompat.Light.DarkActionBar
to:
Theme.AppCompat.Light.NoActionBar
Then, (in java-kotlin side), setup the Toolbar:
// Note that the Toolbar defined in the layout has the id "my_toolbar"
setSupportActionBar(findViewById(R.id.my_toolbar))
And give the Toolbar an id.
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
Then you should be good to go.

https://github.com/DonaldDu/FixUnhandledEvent
android.view.View$OnUnhandledKeyEventListener is add in api28.
If runtime device below 28, can't find the class, but run without fatal error.
We can inject the class in debug mode to ignore error message.
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//inject class when api<28 && debug==true
debugImplementation 'com.github.DonaldDu:FixUnhandledEvent:1.0'

It's not an error but a warning it can be ignored by the addition of the following code in my build.gradle (app level) the file works in my case. Then sync and build the project. Hopefully, it fixes the issue.
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "26.+"
}
}
}
}
Reference to the gist

Downgrading to sdk 27 as one of the other post suggested came with a new set of problems for me.
see: Android - resource linking failed / failed linking references
Adding an entry to my build.gradle (app level) solved the issue for me.
dependencies {
...
implementation 'androidx.core:core:1.5.0-alpha05'
...
}
Here's where I got the idea to try this:
https://github.com/android/sunflower/issues/295#issuecomment-649630057

There's problem with library ~-v7:28.0.0. There are two solutions, your can either download compile and targetSdkVersion to 27 or upgrade Android Studio to latest version (3.2.x higher).

Add multidex support library to your dependencies
com.android.support:multidex:1.0.3

You can fix it easily,
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
and Open style.xml under values and change to
style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Related

Layout Preview is not displaying layout when Material Design is added

I am working on an Android Application. Everything seems perfect until I decided to use Material Design in my theme. After adding Material Design Theme, layout preview is not displaying preview but works perfectly when build on the phone. Everything works perfectly when removing material design components used in xml.
Attaching my code:
activity_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
tools:context=".home.Home">
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:id="#+id/logout"
android:text="LOG OUT"
/>
</RelativeLayout>
HomeActivity.java
package com.****.*****.home;
import androidx.appcompat.app.AppCompatActivity;
import com.hashimshafiq.prepup.R;
import butterknife.OnClick;
public class Home extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(this);
}
#OnClick(R.id.logout) void onClickLogout(){
}
}
build.graple (app module)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.****.*****"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
buildToolsVersion = '28.0.3'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "com.google.android.material:material:1.1.0-alpha09"
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.facebook.android:facebook-android-sdk:5.2.0'
}
build.gradle (Prepup)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTextField" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxBackgroundColor">#color/background</item>
<item name="boxStrokeColor">#android:color/white</item>
<item name="hintTextColor">#android:color/white</item>
</style>
</resources>
The error that mostly occurred in Layout Preview
java.lang.IllegalArgumentException: java.lang.ClassCastException#b83d5b8
at sun.reflect.GeneratedMethodAccessor509.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at android.animation.PropertyValuesHolder_Delegate.callMethod(PropertyValuesHolder_Delegate.java:108)
at android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(PropertyValuesHolder_Delegate.java:143)
at android.animation.PropertyValuesHolder.nCallFloatMethod(PropertyValuesHolder.java)
at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)
at android.animation.ValueAnimator.start(ValueAnimator.java:1069)
at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)
at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1081)
at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1142)
at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1227)
at android.animation.AnimatorSet.start(AnimatorSet.java:729)
at android.animation.AnimatorSet.start(AnimatorSet.java:684)
at android.animation.StateListAnimator.start(StateListAnimator.java:188)
at android.animation.StateListAnimator.setState(StateListAnimator.java:181)
at android.view.View.drawableStateChanged(View.java:21105)
at android.widget.TextView.drawableStateChanged(TextView.java:5283)
at androidx.appcompat.widget.AppCompatButton.drawableStateChanged(AppCompatButton.java:156)
at android.view.View.refreshDrawableState(View.java:21160)
at android.view.View.dispatchAttachedToWindow(View.java:18379)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:335)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:391)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:195)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:540)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:666)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Note: App is working perfectly on Moble but Layout preview is not displaying the layout and that is the issue.
Thanks in advance.
Edit
I have done the following solutions but nothing happens and error persists.
Invalidate Cache and Restart
Clean Build
Revert the material design to version 1.0.0
Refresh the layout after following changes:
1) Remove the line tools:context=".home.Home" from parent layout in file activity_home.xml.
2) Change name of class Home to HomeActivity in file HomeActivity.java.
3) Resync project with gradle files.
Edit:
This isn't due to errors in XML/backend code. It is due to a bug in Android Studio which can be tracked here it is apparently fixed in version 3.6 Canary 3 (API 29 and material_version = '1.1.0-alpha08') as well.

Android Studio 3.1.3 having issues with Constraint layout

I'm trying to start a new project here but this problem is appearing. I can run the project and deploy it in an emulator but this Render problem and Using private resources is ticking me off. I've already tried all the possible solutions found in the internet but it just can't solve the problem
<?xml version="1.0" encoding="utf
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</android.support.constraint.ConstraintLayout>
Style
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.acer.myapplication3"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:28.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- core:3.0.2'
}
Had the same issue - went to SDK manager and installed additional SDK platforms; Oreo 8.1. It seems the issue was that the 'new' API 28 still has issues. It says partially installed, but I basically just checked the boxes for lower API's and it downloaded/installed:
Additionally, I changed my build.gradle file's SDK version, buildTools, appcompat, and design versions as below. It works now and I will move back to API 28 at a later stage when these issues have been resolved.
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 27
...
dependencies {
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.0.0'
}
You just need to change the following codes from the dependencies section of your build.gradle file:
From:
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc02'
To:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
And then sync your project.
I had the same issues. For me, the reason is my project "Automatically convert third-party libraries to use AndroidXhas". Check if your problem same as mine? please simply follow the two steps described here.
to make it easy:
1st step:
Please check your gradle.properties, if you see the following lines, you might have the exact same issues as mine. You can firstly delete them.
android.useAndroidX=true
android.enableJetifier=true
2nd step: in main activity, I changed
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
into
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
Everything works all of sudden!
Try to use this:
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
}
Instead of constraint-layout:1.1.2.
This solved my issue.
Add 'Base.' before 'Theme.AppCompat.Light.DarkActionBar'
in styles.xml .
Worked for me.
On the left-hand side, click app.
Then, open the res folder.
Open up the values folder.
Click on the 'styles.xml' folder.
Change the parent variable to "Base.Theme.AppCompact.Light.DarkActionBar"
Make sure you unchecked OFF LINE option in settings > gradle, then
sync the project again while connected on network

CoordinatorLayout not working in Android Studio 3.1.3?

I know this question has been asked a lot of times but I have tried most of the solutions, and none worked for me.
This is the first time that I'm working on android studio 3.1.3, and I was following a tutorial on how to create a simple app using the basic template option from the android studio. The problem that I'm facing is;
Render Problem Failed to find style 'coordinatorLayoutStyle' in
current theme
I have tried adding this to the build.gradle file:
compile 'com.android.support:design:24.1.1'
Also this into the style.xml
<style name="AppTheme.NoActionBar">
<item name="coordinatorLayoutStyle">#style/Widget.Design.CoordinatorLayout</item>
</style>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
Couldn't resolve resource #style/Widget.Design.CoordinatorLayout<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
build.gradle
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.notes"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
I was having the same problem. I tried following steps from here, but still the problem persists. I think it is a common issue in android studio 3.0+, Hopefully they will fix it next update. In the Android Studio Preview 3.2 it works fine. Download Android Studio Preview and visit here to learn how to run it alongside with Android Studio stable version
Or you can try to lower your design library version to 27. (And the compile sdk version also to 27)
dependencies { implementation 'com.android.support:appcompat-v7:27.0.2' implementation 'com.android.support:design:27.0.2' }
Try adding "Base" before Theme in styles.xml as show : - "Base.Theme.AppCompat.Light.DarkActionBar"
Permanent solution for this problem: change your build gradle (module app) to implementation com.android.support:appcompat-v7:28.0.0-alpha1.
change your build gradle (module app)
from : com.android.support:appcompat-v7:28.1.1-alpha3
to : com.android.support:appcompat-v7:27.1.1
1.try this first : make changes in Gradle (module app) for appcompat:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
2. If it doesn't work clean your project and then again build it.
In my case, it worked.

Failed to find style 'coordinatorLayoutStyle' in current theme

I'm using the latest version of android studio (3.0), along with latest build tools (27) and similar API level.
The layout does not get rendered in the design tab and it's causing a lot of trouble especially that I'm using coordinator layout.
How do I get around this problem?
I solved this rendering problem by simply inserting this line into the application theme (the app theme is usually placed in styles.xml).
[SDK 28]
<style name="AppTheme">
<item name="coordinatorLayoutStyle">#style/Widget.Support.CoordinatorLayout</item>
</style>
[SDK 27]
<style name="AppTheme">
<item name="coordinatorLayoutStyle">#style/Widget.Design.CoordinatorLayout</item>
</style>
As suggested by #Chris. If the IDE does not find the CoordinatorLayout in Widget.Support or Widget.Design, just start typing "CoordinatorLayout" and it should give you some options.
Turns out the new SDK 28 is unfortunately introducing this error on Android Studio when you create a new project.
How to solve:
Check your build.gradle (Module: app) file and change:
compileSdkVersion 28
targetSdkVersion 28
To:
compileSdkVersion 27
targetSdkVersion 27
Also, make sure you are using the right dependencies version:
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' in
build.gradle(module) change alpha 3 to alpha 1. sync and you should be good to go. I spent almost a day trying to figure this out. none of these answers worked for me. hope this helps
I was also facing the same problem. Nothing like changing theme from Layout preview window helped me.
Solution: I updated my build.gradle(app) with:
dependencies {
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
}
One more thing:
compileSdkVersion 27
targetSdkVersion 27
<style name="Theme.Shrine" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="coordinatorLayoutStyle">#style/Widget.Support.CoordinatorLayout</item>
</style>
Add in your material theme.
For Android Studio 3.1.4 users:
I've tried marked answer but it didn't work for me.
Inserting this line:
<style name="AppTheme.NoActionBar">
<item name="coordinatorLayoutStyle">#style/Widget.Design.CoordinatorLayout</item>
</style>
into the application theme doesn't solve the rendering problem so I've undone that change.
Solution:
I've made this changes in my build.gradle(Module:app) file:
Before change:
android {
compileSdkVersion 28
defaultConfig {
targetSdkVersion 28
}
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support:design:28.0.0-rc01'
}
After change:
android {
compileSdkVersion 27
defaultConfig {
targetSdkVersion 27
}
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
It worked for me perfectly. Hope that will be useful.
Thanks for the response, I found the solution tinkering with the code,
I had tools:showIn attribute enabled in the parent layout of a fragment, which I moved to a viewpager, it was previously embedded in a host activity, lint did not catch it though, which is a bit surprising.
I think it is a common issue in android studio 3.0+,
Hopefully they will fix it next update. In the Android Studio Preview 3.2 it works fine.
Download Android Studio Preview
As an aside, in design view of Android Studio, if I add the following to the styles.xml file:
<style name="Coordinator">
<item
name="coordinatorLayoutStyle">#style/Widget.Design.CoordinatorLayout</item>
</style>
and add the following to the CoordinatorLayout in the layout's xml resource file
<android.support.design.widget.CoordinatorLayout
android:theme="#style/Coordinator"
android:orientation="vertical"
android:id="#+id/sample_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/sample_background"
tools:theme="#style/Coordinator">
then, at least, the design view stops generating the missing coordinatorLayoutStyle error.
My Android studio version 3.1.3.
i'm worked with uninstall ALL SDK version 28. Step is Open SDK Manager > SDK Platforms > Show package Details > Untick SDK 28 > apply and Create new project.
I have the same problem but on the Android studio 3.1.4
So, at first I have done the following in build.gradle
Replace this:
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.android.support:support-v4:28.0.0-rc01'
with that:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'
But somehow after project rebuild the problem repeats again.
So, I have go this way:
Here is my project gradle.build
buildscript {
ext.kotlin_version = '1.2.41'
ext.android_support = '27.1.1'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And here app build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
applicationId "*****.******"//Replace with your own ID
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
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'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
And this solve my problem
Thank you
I will post an answer The other answers may work but no one should need to download Preview Version and doing Material Design with no Action Bar is not the way to START developing apps with Android Studio
Our version of Android Studio is 3.1.4
Our default API is 28
Our FIX is to downgrade to API 26 YOU do this by clicking File -> Project Structure then highlight app Under the Properties TAB Change Compile Sdk version to API 26 Now click on the Falavors TAB and change Target Sdk version to 26
Then in build.gradle(module:app) add these changes
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
I guess one could always justify this slow FIX by Google to learn to use the ToolBar
This maybe existing issue: https://issuetracker.google.com/issues/37048767
Render using other versions of Android (say Android API 22).
Or check for any typos or invalid XML entries.
Refer here: Missing styles. Is the correct theme chosen for this layout?
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="coordinatorLayoutStyle">#style/Widget.Design.CoordinatorLayout</item>
</style>
just add coodrinatorLayoutStyle as an item in style.xml and it worked for me.
Just Change implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' and
'com.android.support:design:28.0.0-alpha3' to alpha 1.
That's how i solved the problem.
I solve this problem when update all SDK tools in IDE and update Android Studio to 3.2.1
its working for me try it
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
}
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
This is sdk 28 issue
Check your build.gradle (Module: app) file and change:
compileSdkVersion 28
targetSdkVersion 28
To:
compileSdkVersion 27
targetSdkVersion 27

android.support.v7.widget.Toolbar VectorDrawableCompat IllegalStateException when using support lib 24+

I've started a new project in Android Studio and configured my gradle build settings. When I add an android.support.v7.widget.Toolbar to a layout, I get the following error when in design view. Keep note that this error only shows up when previewing with an API less than 21 (specifically APIs 16 - 19). Everything works fine when I preview with API 21 - 24.
I have looked at a number of solutions and tried them, but none have solved the issue. One thing I tried doing was adding this to my gradle:
vectorDrawables.useSupportLibrary = true
But that didn't solve the issue. I tried configuring my compiledSdkVersion to 23, buildToolsVersion to 23.0.3. This did not change anything. If I change the support library versions to 23.4.0 or below, then the issue is resolved. As soon as I change it back up to 24.0.0 or higher then it returns.
Clearing the cache, cleaning the project and rebuilding, and invalidating the cache and restarting did not solve the issue.
The following classes could not be instantiated:
- android.support.v7.widget.Toolbar (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when in the IDE
Exception Details
java.lang.IllegalStateException: This app has been built with an incorrect configuration.
Please configure your build for VectorDrawableCompat.
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:692)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:67)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:298)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:229)
...
invalid drawable tag vector
Here is my app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1" // https://developer.android.com/studio/releases/build-tools.html
defaultConfig {
applicationId "org.path.path"
minSdkVersion 16
targetSdkVersion 23
versionCode 0
versionName "0.0.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
ext {
supportLibVersion = '24.0.0' // https://developer.android.com/topic/libraries/support-library/revisions.html
}
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
}
My project build.gradle is using classpath 'com.android.tools.build:gradle:2.1.2'
This is the toolbar xml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?attr/actionBarSize"
android:elevation="4dp"
android:background="#color/colorPrimary"
app:theme="#style/ActionBarThemeOverlay"
app:popupTheme="#style/ActionBarPopupThemeOverlay"/>
And finally, my styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<!-- ActionBar -->
<style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Dark" />
<style name="ActionBarThemeOverlay" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textColorPrimary">#color/text_on_primary</item>
<item name="android:textColorSecondary">#color/subtitle_on_primary</item>
</style>
Is this a bug, or am I just not able to use the support library versions 24 or higher? I'm not aware of any other configurations to change as the exception tried to direct.
Check this issue:
appcompat-v7 24.0.0 is incompatible with rasterized vectors
Make sure you are using gradle version greater than 2.0
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}

Categories

Resources