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.
Related
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">
I tried looking other similar questions on stackoverflow, they advice us to changw version of "buildToolsVersion" but I dont see word like that in my gradle file.
My Gradle File (PROJECT):-
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My build.gradle (Module:app): This the my second gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.dhruv.testhello"
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 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
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 had the same problem. I searched so much and I finally found that appcompat-v7:28.0.0-alpha3 has some bug with "Design View" part of Android Studio.
So I suggest to change com.android.support:appcompat-v7:28.0.0-alpha3 to com.android.support:appcompat-v7:28.0.0-alpha1 version and then click File -> Invalidate Caches / Restart. Volla everything is OK.
Of course you should have internet access to download com.android.support:appcompat-v7:28.0.0-alpha1
I was helped by Hossein Seifi's reply but with a change
implementation 'com.android.support:design:28.0.0-alpha3'
to
implementation 'com.android.support:design:28.0.0-alpha1'
and click File -> Invalidate Caches / Restart
Update 2
As you can see in support 28.0.0 release notes.
This will be the last feature release under the android.support
packaging, and developers are encouraged to migrate to AndroidX 1.0.0
Android will not update support libraries from now. So I suggest you migrate to androidx before they deprecated support libraries.
Update
Support 28.0.0 is released, so you can use this stable version.
implementation 'com.android.support:design:28.0.0'
I suggest never use alpha versions, because alpha, beta versions have bugs, that are testing libraries.
module app gradle file looks like this...In your file you are missing buildToolsVersion, adding this may help you
apply plugin: 'com.android.application'
android {
//changes
compileSdkVersion 26
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.dhruv.testhello"
minSdkVersion 24
targetSdkVersion 26
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'])
//changes
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
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'
}
In styles.xml,
Changing the theme from Theme.AppCompat.Light.DarkActionBar to Base.Theme.AppCompat.Light.DarkActionBar has worked for me.
yes its work,
implementation 'com.android.support:design:28.0.0-alpha3'
to
implementation 'com.android.support:design:28.0.0-alpha1'
After that got to File and click -> Invalidate Caches / Restart
At the time of this answer Android Studio 3.1.4 is out with Android Support 28.0.0 Release Candidate(Potential Final, Beta) so please update.
Well, here is a config that will certainly work for you.
targetSdkVersion 28
com.android.support:*:28.0.0-rc01
Where * is the resource type.
Open, res>values>styles.xml, here you will find a line:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
replace the line with:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
That means: Add the word "Base." starting the name of the parent theme.
Open, res --> values --> styles.xml, here you will find a line like this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
change it to:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
In otherwords, change DarkActionBar to NoActionBar
24 hours ago my project built perfectly, no errors. Without changing a single piece of code, it will no longer build when I have resumed work.
Checking out to older working commits now produces the same error.
These are the error codes I get:
Information:Gradle tasks [assemble]
Error:(9, 5) error: resource android:attr/dialogCornerRadius not found.
/home/liam/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0-alpha1.aar/536e4dd78846259cf8bef0fd6a3ea0e6/res/values/values.xml
I think that this has been caused by Android P being released and my Android Studio automatically upgrading or something like that. Which would explain why old commits that worked get this same error.
This would be a very new issue, which would explain why I cannot find a solution to it yet.
Searching these error codes leads to a similar issue that was resolved by changing the SDK version in the gradle build file. My problem differs from this because changing to SDK 28 (I'm pretty sure 28 doesn't even exist) leads to android studio saying this package isn't available/doesn't exist for download.
How to find issue Android SDK 3.0 Error:(9, 5) error: resource android:attr/colorError not found
Clicking on the first mentioned error codes leads to a file called v28/values-v28.xml being opened.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.Theme.AppCompat" parent="Base.V28.Theme.AppCompat"/>
<style name="Base.Theme.AppCompat.Light" parent="Base.V28.Theme.AppCompat.Light"/>
<style name="Base.V28.Theme.AppCompat" parent="Base.V26.Theme.AppCompat">
<!-- We can use the platform styles on API 28+ -->
<item name="dialogCornerRadius">?android:attr/dialogCornerRadius</item>
</style>
<style name="Base.V28.Theme.AppCompat.Light" parent="Base.V26.Theme.AppCompat.Light">
<!-- We can use the platform styles on API 28+ -->
<item name="dialogCornerRadius">?android:attr/dialogCornerRadius</item>
</style>
</resources>
Here are my gradle files:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.timelord.timelord.timelord"
minSdkVersion 24
targetSdkVersion 26
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:26.1.0'
implementation 'com.android.support:design:+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation files('libs/joda-time-2.9.9.jar')
}
And
// 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.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You have the design lib version with + in your build.gradle which means it will download the latest version. So please set it to 26.1.0 and it should work. The support 28 is in alpha and was released yesterday with the new android P preview
Make sure in your app's build.gradle you have these:
dependencies {
compile 'com.android.support:support-v13:27.+'
compile 'com.android.support:design:27.+'
}
After updating support library version 27.1.0 Android Studio unable to render CardView. It shows error message as
failed to find style 'cardView Style' in current theme
But no error in compiling and no difference while seeing on the phone.
I have reverted the support library version to 27.0.2 and it's rendering fine.
The issue with support library or Android studio? How to fix this?
App Level Gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.tmmmt.tmmmt"
minSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
buildConfigField 'String', 'FS_CLIENT_ID', FOURSQUARE_CLIENT_ID
buildConfigField 'String', 'FS_CLIENT_SECRET', FOURSQUARE_CLIENT_SECRET
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
buildConfigField 'String', 'FS_CLIENT_ID', FOURSQUARE_CLIENT_ID
buildConfigField 'String', 'FS_CLIENT_SECRET', FOURSQUARE_CLIENT_SECRET
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "default"
productFlavors {
dev {
dimension "default"
versionNameSuffix "-dev"
buildConfigField 'String', 'BASE_URL', BASE_URL_DEV
manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_DEV]
}
beta {
dimension "default"
versionNameSuffix "-beta"
buildConfigField 'String', 'BASE_URL', BASE_URL_BETA
manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_BETA]
}
live {
dimension "default"
buildConfigField 'String', 'BASE_URL', BASE_URL_LIVE
manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_LIVE]
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.anko:anko-common:$anko_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:support-v13:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:cardview-v7:$support_version"
implementation "com.google.firebase:firebase-messaging:$play_version"
implementation "com.google.android.gms:play-services-maps:$play_version"
implementation "com.google.android.gms:play-services-location:$play_version"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation 'com.squareup.okhttp3:okhttp:3.8.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.wang.avi:library:2.1.3'
implementation 'com.tmmmt.library:arrowtab:1.3'
implementation 'com.github.stfalcon:chatkit:0.2.2'
implementation 'com.amazonaws:aws-android-sdk-core:2.6.16'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.6.16'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.16'
implementation 'com.orhanobut:logger:2.1.1'
implementation 'com.tmmmt.library:animations:0.6'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
compile('io.socket:socket.io-client:1.0.0') {
exclude group: 'org.json', module: 'json'
}
/*Fort*/
implementation project(':FortSDKv1.4.1')
implementation 'com.victor:lib:1.0.1'
implementation 'com.shamanland:fonticon:0.1.8'
implementation('com.nispok:snackbar:2.11.0') {
exclude group: 'com.google.android', module: 'support-v4'
}
implementation 'com.google.guava:guava:23.0-android'
implementation 'org.bouncycastle:bcprov-jdk16:1.46'
implementation 'commons-codec:commons-codec:1.10'
/*Fort*/
}
apply plugin: 'com.google.gms.google-services'
Project Level Gradle:
buildscript {
ext.kotlin_version = '1.2.30'
ext.anko_version = '0.10.1'
ext.support_version = '27.1.0'
ext.play_version = '11.8.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:4.3.2"
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://mymavenrepo.com/repo/eDGOo6Dqr4f6uNA0HoWX/"
credentials {
username = 'myMavenRepo'
password = 'tmmmt123'
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Update:
There is no such error from Android Studio 3.2. The error was gone completely.
Checking the source of CardView one can see that the constructor
public CardView(#NonNull Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
initialize(context, attrs, 0);
}
has been changed to
public CardView(#NonNull Context context, #Nullable AttributeSet attrs) {
this(context, attrs, R.attr.cardViewStyle);
}
And the new attribute cardViewStyle is defined in the library. I guess that the Android Studio preview is not including the value for this attribute from the library, for some reason. I'm not sure if it usually resolves custom attributes defined in libraries and this is a bug, or if this is intended.
Workaround 1
Resolve the attribute in your theme (maybe only in debug version), this way the error is gone. #style/CardView is already defined in the support library so you don't need to create the style, just reference it.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="cardViewStyle">#style/CardView</item>
</style>
Be sure to use AppTheme in the layout preview and clean build.
Workaround 2
Add the style with tools namespace so that it won't affect your production code. The rendering error will be logged, but you will see the CardView anyway
<android.support.v7.widget.CardView
tools:style="#style/CardView"
...
Good news
Android Studio 3.1 seems to be handling this correctly, no workaround needed (the error in the layout preview is still logged though).
On Android Studio 3.2 (currently in Canary channel) the error is gone.
I also had the same problem, so I added
<item name="cardViewStyle">#style/CardView</item>
in my styles.xml file. But it was showing a warning "The resource #style/CardView is marked as private in com.android.support:design".
So, after that I tried this one
<item name="cardViewStyle">#style/CardView.Light</item>
and this worked for me. I am using Android Studio 3.1.4 and Gradle 4.4.
updating the CardView from 27.1.1 to 28.0.0-alpha3 fixed the XML preview for me on AS 3.1.3.
implementation "com.android.support:cardview-v7:28.0.0-alpha3"
it still complains, but it renders the preview.
there's also a new androidx class now, which should be the same:
implementation "androidx.cardview:cardview:1.0.0"
when updating com.android.support:design to 28.0.0-alpha3, it hints for:
The resource #style/CardView is marked as private in com.android.support:design
downgrading back to API 27 with buildTools 27.0.3 & supportLibrary 27.1.1 also prevents the issues. might upgrade to 28.0.0 with Android Studio 3.2 then.
In my case the reason of the error with CardView was because of the wrong listheader attribute of a child Spinner. Alongside the failed to find style 'cardView Style' in current theme error message I got Spinner adapter view type count must be 1, so the roots of the CardView failing were surprisingly in Spinner rendering failure.
How to find issue to this error when I did a make I have got this error message :
Error:(9, 5) error: resource android:attr/colorError not found
Thing strange I've 2 build.gradle files :
Here my build.gradle (Project:Projectname) File :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here my build.gradle (Module:app) File :
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
defaultConfig {
applicationId "org.acme.nfcedit"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
This file appears /home/users/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/c41e5bc4d98504dc222d4eca88ab6d1b/res/values-v26/values-v26.xml content
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.Theme.AppCompat" parent="Base.V26.Theme.AppCompat"/>
<style name="Base.Theme.AppCompat.Light" parent="Base.V26.Theme.AppCompat.Light"/>
<style name="Base.V26.Theme.AppCompat" parent="Base.V26.Theme.AppCompat">
<!-- We can use the platform styles on API 26+ -->
<item name="colorError">?android:attr/colorError</item>
</style>
<style name="Base.V26.Theme.AppCompat.Light" parent="Base.V23.Theme.AppCompat.Light">
<!-- We can use the platform styles on API 26+ -->
<item name="colorError">?android:attr/colorError</item>
</style>
<style name="Base.V26.Widget.AppCompat.Toolbar" parent="Base.V7.Widget.AppCompat.Toolbar">
<item name="android:touchscreenBlocksFocus">true</item>
<item name="android:keyboardNavigationCluster">true</item>
</style>
<style name="Base.Widget.AppCompat.Toolbar" parent="Base.V26.Widget.AppCompat.Toolbar"/>
</resources>
I don't know what's mmeaning ?android:attr/colorError
Thanks
The attribute named "android:attr/colorError" is referenced by the appcompat library at API 26 and above. But the build is compiling with sdk version 22.
So, inside your app module's build.gradle, increase your compileSdkVersion to 26 to make it agree with the version of the appcompat library you are using.
In other words, right now, you have:
compileSdkVersion 22
implementation 'com.android.support:appcompat-v7:26.1.0'
But, those two versions should be in agreement. So, see what happens with:
compileSdkVersion 26
implementation 'com.android.support:appcompat-v7:26.1.0'
Change compileSdkVersion 22 to compileSdkVersion 26.
Here is an update for RN>0.60. Inside your android\build.gradle, place the following inside the allprojects block to ensure subprojects have an updated compileSdkVersion.
subprojects {
afterEvaluate {
project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion = 28
buildToolsVersion = "28.0.3"
}
}
}
}