Rendering error in constraint layout - android

So tbh I am a bit of a noob when it comes to android programming. Started an app development yesterday after a long hiatus. I have worked with Android Studio and Relative / Linear layout in the past but with the new constraint layout I am having rendering issues. It just refuses to render the text view. I have tried to search and tried every possible fix for the same. I have attached a screenshot of the same

Try rebuilding your project as follows; Build >> Rebuild Project. Somethings the you can't see the design until you've made a successful build.
Also, check that you have included this in your build.grade dependencies
implementation 'com.android.support.constraint:constraint-layout:1.1.0'

Related

Android Studio (Dolphin | 2021.3.1) & (Electric Eel | 2022.1.1) does not show layout preview

I'm using Android Studio Dolphin | 2021.3.1 & Electric Eel | 2022.1.1
After updating Android studio chipmunk | 2021.2.1 to Android studio Dolphin | 2021.3.1 my all project design preview and layout preview not showing.
If anyone solved this issue please help me.
I have tried all possible ways but didn't find any solution for this.
Below are points that I have tried
Invalidate caches.
Restart IDE.
Repair IDE.
Update Gradle plugin version to 7.3.0 from setting project structure (No working)
Check the Below screenshot so everyone gets an idea of what I have issue faced.
Thanks in advance.
For me, some layouts are working fine but in some layouts, I am getting the below error which used to work in earlier versions of Android Studio.
The same issue I faced in Android (Electric Eel | 2022.1.1). Still, this Issue continues.
I was able to fix this by changing the preview's theme from App.Starting [default] to my app's theme from the Design Tab
After alot of searching and testing, I upgraded my gradle version and its work for me.
Just goto File -> Project Structure or press Ctrl + Alt + Shift + S and then upgrate the gradle version as shown in the image below and then invalidate cache and restart the Android Studio and its working
As shown in the image I upgrade my gradle.
Apparently, there are many people reporting the exact same issue to Google but no concrete solution has been given so far:
Issues with Layout Preview in AS since Dolphin
Layout rendering inside AS stops on most of layout after upgrade to 2021.3.1 RC 1 (worked on Chipmunk)
NPE in AarResourceRepositoryCache.createCachingData (AS Dolphin+)
Dolphin continuously refuses to show Design Layouts
Layout editor preview almost always broken
Layout previews have stopped working
I tried most of the suggestions from the other answers, but the only thing that has worked for me so far was upgrading to Flamingo (2022.2.1 Canary 10) or downgrading to Chipmunk (2021.2.1 Patch 2).
These solutions are obviously far from ideal, but until Google decides to fix this in either Dolphin or Electric Eel, I believe that's what we're stuck with.
In my case, I found two situations.
1. Include
the android studio can't show the XML if it contains the "include" tag.
My project has more than 100+ XML files that have the include, and none of them can show the preview. Otherwise, it was fine.
Setting the app theme doesn't work for this case.
2. Setting app theme
On top of the preview screen, you can select the app theme. (If you can't find it, try enlarging the android window itself. Then the hidden app theme menu will be revealed.)
Then, try setting some theme, such as "AppTheme" or "BaseTheme", etc. Then, for some cases, this will show you the preview.
I tried to update gradle but not work with me.
so after that i changed them from
Theme.MaterialComponents.DayNight.NoActionBar
to
Theme.Material3.DayNight.NoActionBar
work with me
if this solution does not work with you
add this line to root group view in layout
android:theme="#style/Theme.MaterialComponents.Light.DarkActionBar.Bridge"
another solution
down material version to this version
material_version = '1.6.1'
I hope that helps you.
I have same issue as above just solved by doing below things
Setting - SDK tools and check for Android Emulator Update
just Update it and Rebuild project and Done
No need to downgrade API versions.
Note - if not work after it just try to invalidate cach and restart
Option 2
after doing above task try to just update or select app theme from above preview design
To solve temporary this issue. Change theme for preview using "AppTheme". This is work for me. For detail see the attachment file image
Use material:1.8.0-alpha01 dependency. alpha02 has issue showing preview.
New solution:
I just tried the latest canary build of Android Studio Flamingo and it seems that the layout preview is now fixed! At least it works for me again without any problems, with MDC 1.8.0-alpha03 and the latest gradle plugin and gradle version.
Old solution:
It appears to be a bug in Dolphin in connection with API 33, but for me at least the layout preview toolbar is shown. In case the preview toolbar is somehow accessible, the following workaround solves the disappeared preview (at least for me):
Select API 32 in the layout toolbar instead of the preselected API 33.
Then the preview is shown to me as it should and I do not have to downgrade anything and can use the latest gradle version.
Change the AGP Version and Increase Gradle version if you have not in Project structure > Project to latest version the click apply and wait for gradle to complete. After completing, Just Invalidate Cache and restart. It worked for me.
Starting with Android Studio Chipmunk, if you're seeing java.lang.NoSuchFieldError: view_tree_saved_state_registry_owner or java.lang.ClassNotFoundException: androidx.savedstate.R$id in the issues panel, make sure to include a debugImplementation dependency to androidx.lifecycle:lifecycle-viewmodel-savedstate in your module.
If you're seeing java.lang.NoSuchFieldError: view_tree_lifecycle_owner in the issues panel, make sure to include a debugImplementation dependency to androidx.lifecycle:lifecycle-runtime in your module.
If you're seeing java.lang.NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.PoolingContainer or java.lang.NoClassDefFoundError: androidx/customview/poolingcontainer/PoolingContainerListener in the issues panel, make sure to include a debugImplementation dependency to androidx.customview:customview-poolingcontainer in your module.
Issue tracker : https://issuetracker.google.com/issues/247058594
Workaround Solution : File - Project Structure -
I have also encountered this issue. Switching Android Gradle Plugin to 7.3.0 for all projects and 7.4 for gradle solve this problem.
Try to remove/modify any drawable resource files that you are using as style/background in your layout. It may cause Render problem/Touch size/Touch Target too small. In my case I was using such resource files, after modifying those, the layout is visible to me. Thanks.
I had the same issue and solved it by ignoring some errors in the issue panel
Not this specific issue, this is for example sake
Don't use alpha version. Use this
implementation 'com.google.android.material:material:1.7.0'
In my case solve this issue I do following steps
First I just update Gradle plugin version to 7.3.0 from setting project structure (No working)
after that I also update com.google.gms:google-services version to 4.3.14
now every things work fine.
I was using custom views, styles and fonts from a library and ran into this when upgrading to Dolphin. I fixed the issue by upgrading the libraries compile SDK to 33. Upgraded gradle to 7.3 and upgraded androidx.appcompat:appcompat to 1.4+
Once you do that, invalidate caches and rebuild and it should work.
Google is aware of this issue https://issuetracker.google.com/issues?q=dolphin%20layout%20preview
Downgrading to Chipmunk until a patch is released will also fix the issue if you can't or wont upgrade.
Try to upgrade your gradle version to latest (whatever it may be). Mine Worked
If all these solutions are not working then you can try below option as well.
Disable lottieAnimation in the xml file, and reBuild the app, then it is working fine now.
For you that because of others dependencies cannot update the Android Gradle Plugin:
You'll have to wait a little bit, the devs are already aware. There should eventually be a version to correct this.
For now what you can do to keep working is downgrading the Android Studio Version to Chipmunk | 2021.2.1 (or older)
Maybe it's not going to fix your problem. But it may helps someone who gets into the same trouble as I had. I have an extended layout, the exception says it's not able to initial this class, and pointing to a singleton property variable.
private SingletonProperty property = SingletonProperty.getInstance();
Turns out it's not possible to have a singleton field in a layout class(which it's okay before Android Studio Dolphin). Everything works fine after I move it into several methods. Don't forget to build your project after this.
For me, disabling assertions fixed the issue.
I found the fix here: https://issuetracker.google.com/issues/255525863
To disable assertions, add -da to Custom VM Options:
In case that Android Studio won't start after applying the new options,
the custom VM options file is located at:
macOS:
~/Library/Application Support/Google/AndroidStudio2021.3/studio.vmoptions
I had the same problem if you are using custom views in your layout, checkout this answer https://stackoverflow.com/a/66337620/14599955.
Open Layout Validation tab from right side or search it from toolbar search menu
now see the issue in my case is inside MaterialAutoCompleteTextView
after investigating issue is
android:fontFamily="More Fonts..." font is not point to right one
I also had the problem of the layout page not appearing and it was not solved in any way until I made a copy of it and deleted the entire layout one by one to find out which view had the problem. It is interesting that the copy of the layout was intact and worked exactly.
Frankly guys tried everything as suggested in mentioned answers, but doesn't seems to work for me, might be a recent Android Studio bug.
Sharing something what worked for me (workaround, not a fix)
I accidentally clicked the LayoutValidation tab as mentioned in screenshot, and for now using it to preview my design while updating XML code. Preview gets updated as you make changes.
But yes this might not be helpful if want to make changes using design.
I'm on Android Studio Electric Eel and I managed to fix the issue after a whole day of trying by replacing com.google.android.material:material version 1.8.0 with 1.7.0.
Even though 1.8.0 is now 'stable' it was the one causing the issue.
Downgrade to Android Studio Chipmunk (2021.2.1) Patch 2
https://developer.android.com/studio/archive
It will work after that.
The only way that rendering of XML is going to work is by clearing out all the errors from the issue panels, which in your case from the photo are 4 errors. This worked for me

Can't find "Convert to MotionLayout" in android studio

I have tried adding different implementations for constraintlayout
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
Cleaning the project, still right clicking on constraintLayout does not show "Convert to motionLayout". I need to manually add another xml file under the xml directory for the motion. Looked into other people's problems. Seems they had the dependency issue. Any helps will be appreciated.
The MotionLayout editor is available in Android Studio starting from version 4.0.0. Make sure that you have updated your IDE.
use
"implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
Make sure your project compiles at that point.
Then convert.
This small (< 2min) video shows the conversion:
https://twitter.com/i/status/1187075643118239744

Preview Anko DSL views

I'm looking for a way to preview the rendering of an Anko view DSL in Android Studio. I've searched a lot and found only some deprecated or not working Android studio plugins. Is there a trick or something to make it works ?
The Anko Support plugins doesn't work...
I use Anko support plugins to preview DSL layouts all the time. There may be a few reasons why it may not work in your case:
Your layout should be defined in an external class that implements AnkoComponent interface.
Try rebuilding your project if the layout does not render properly. The preview works after the project is rebuilt.
Try refreshing the layout if that might solve your issue.
Make sure your Anko dependencies are latest and Android Studio 3+.
If you can share more info like the versions of your plugins and your code, maybe I can help pinpoint the exact issue.
Meanwhile here is an article that can surely help you out: https://blog.mindorks.com/how-to-preview-dsl-layouts-made-using-anko-layouts-f885c6bf67b3

android studio project compiled in 2.2p1 strange borders

I upgraded android studio to 2.2.p1 and builded my project without errors. There are some strange borders around views (see att). When I create the new default project and build it in 2.2.p1 the problem is the same. When I do the same in 2.1.1 the app behaviour is normal - without borders. The problem is, that I'm not able to find the cause of this behaviour and build my existing project in 2.1.1 did not help -> there is something "strange" in existing project which was already compiled in 2.2p1. Do you have a idea and solution for this?
thank you for your time and help ... noe
https://code.google.com/p/android/issues/detail?id=210467
I think this is correlated to the bug that is filed.
So long story short, just wait for the fix, OR, downgrade your gradle to
classpath 'com.android.tools.build:gradle:2.1.+'

Android-Studio databinding not working

I wanted to take a look into data binding for Android so it set up a small project. But i can't seem to get it working for Android Studio.
Basically the problem is it doesn't render my layouts in the Android Studio editor because it complains it cannot find the <Layout> and <data> classes. I could run the project though.
I followed the instructions mentioned in https://developer.android.com/tools/data-binding/guide.html. Although there are remarks about lacking Android Studio integration i couldn't find anything about not being able to view the Layout files, as it would be a major drawback.
I have setup
classpath 'com.android.databinding:dataBinder:1.0-rc1'
and
apply plugin: 'com.android.databinding'
compile 'com.android.support:appcompat-v7:21.0.3'
in the gradle files.
I also have the latest Android Studio installed and i already rebuild my project.
EDIT:
I found https://code.google.com/p/android/issues/detail?id=176274 discussion. They are mentioning this issue to be fixed in AI-141.2006197 and i am running AI-141.2017176 which should be later and therefore containing this feature, right?
EDIT 2:
Updated now and also tried with AI-141.2218876, still the same issue.
Make sure the <layout> tag is not capitalized in your XML file! I see that it is capitalized in your question. That won't work.
If this isn't the solution, please update our question to include the full activity and XML layout and stack trace of the build failure.

Categories

Resources