ConstraintLayout 2.0 rendering problems - android

After updating to ConstraintLayout 2.0 I realized that even the simplest layouts can not be previewed properly in Android Studio, both on OS X and Ubuntu.
First, my setup looks like this: I'm using "androidx.constraintlayout:constraintlayout:2.0.0", the version of Android Studio is 4.0.1 (the latest stable release) on both of my computers, the version of Android Gradle plugin is 4.0.1, the version of Gradle is 6.1.1.
Here's an example:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I would expect it to draw the TextView aligned to the top of the screen.
What I end up seeing instead is this:
I tried turning off the experimental rendering engine as AS warned me there might be some issues with it but to no avail.
Is there something obvious I might be missing? Since 2.0.0 was in release for 2-3 days (and the release candidate was available for a wide audience for longer than that), I assume all obvious glitches should've been resolved at this point.
Upd. AS states there is a following rendering problem:
java.lang.NoClassDefFoundError: Could not initialize class androidx.constraintlayout.widget.ConstraintLayout$LayoutParams$Table
at androidx.constraintlayout.widget.ConstraintLayout$LayoutParams.<init>(ConstraintLayout.java:2603)
at androidx.constraintlayout.widget.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:1823)
at androidx.constraintlayout.widget.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:481)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1125)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1097)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:501)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:348)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:404)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:678)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$8(RenderTask.java:809)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Upd. 2 I've submitted a bug report, let's see if this is a bug with Android Studio / Constraint Layout indeed (which I think is not the case).

Ok, in my case this definitely looks like an issue with a project cache. Once I've cleaned it up (Build -> Clean Project), the layout preview started working just fine.

I am having the same issue after updating to 2.0.0, I believe this is an AS/Constraint Layout issue. Using version 1.1.3, for the time being, works just fine.
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Related

Android Lint not detect UnusedAttribute

In an empty project(create from new project),Android Studio can not detect lint issue "UnusedAttribute", neither code editor display hint or run Ananlyze manually(the item is checked).
And there is no lint.xml or lint config in build.gradle file in project.
android studio screenshot
my code is
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World!"
android:paddingHorizontal="52dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:paddingHorizontal is introduced in version 26, and my minSdkVersion is 16.
Also, command line
./gradlew :app:lintDebug
output:lint-results-debug.html also show no detect "UnusedAttribute" problem.
I think it is my env or ide problem, but do not know what is it.
Anyone have this problem?
Additional information:
I want a clean project to figure out this problem and create empty project. In my production project Android studio also can not detect android:paddingHorizontal issue, but can detect android:networkSecurityConfig, and command line output is here:
lint-results-debug.html screenshot

Constraint layout can not be rendered in Android studio

Coding a constraint layout:
<View
android:id="#+id/divider"
style="#style/divider_style"
android:layout_width="0dp"
swedbank:layout_constraintBottom_toBottomOf="parent"
swedbank:layout_constraintLeft_toLeftOf="parent" />
<ImageView
android:id="#+id/some_image"
style="#style/some_style"
swedbank:layout_constraintBottom_toBottomOf="#+id/divider" <!-- This '+' -->
swedbank:layout_constraintRight_toRightOf="parent"
swedbank:layout_constraintTop_toTopOf="#+id/divider" /> <!-- This '+' -->
See the comments: the plusses on those lines must be there for the android studio layout renderer to work. without them you get:
Couldn't resolve resource #id/divider Tip: Try to refresh the layout.
I always thought #+id/ was for the first time you defined an id?
I've experienced IDE problems if I use +'es everywhere some years ago: With goto-definition the IDE would not know which id to go to
Tested on Android studio 2.3.3 and 3.0.1
Seeing as the auto-complete gives you plusses everywhere should i just go with that?
Try adding this to your dependencies section in the gradle
compile 'com.android.support.constraint:constraint-layout:1.0.2'

App in Android Studio - XML Layout doesn't appear

I have a problem after updating Android Studio version from 2.2.* to 3.0.1. The problem is XML Layout doesn't show in design mode.
API / Device changing didn't solve my problem.
The error message is:
Exception raised during rendering: android/text/TextUtils
Details:
java.lang.ClassFormatError: android/text/TextUtils at
android.content.res.Configuration.setLayoutDirection(Configuration.java:1779)
at
android.content.res.Configuration.setLocales(Configuration.java:1725)
at
android.content.res.ResourcesImpl.calcConfigChanges(ResourcesImpl.java:484)
at
android.content.res.ResourcesImpl.updateConfiguration(ResourcesImpl.java:365)
at android.content.res.ResourcesImpl.(ResourcesImpl.java:161)
at
android.content.res.Resources_Delegate.initSystem(Resources_Delegate.java:90)
at
com.android.layoutlib.bridge.android.BridgeContext.initResources(BridgeContext.java:255)
at
com.android.layoutlib.bridge.impl.RenderAction.setUp(RenderAction.java:242)
at
com.android.layoutlib.bridge.impl.RenderAction.init(RenderAction.java:134)
at
com.android.layoutlib.bridge.impl.RenderSessionImpl.init(RenderSessionImpl.java:165)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:382)
at
com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at
com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
at
com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
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)
Even if I create clean xml layout, I still get the same error message.
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Does anyone face this problem before and what is the solution for this?
Update. I did downgrade to 2.2.2 and everything work now. Thanks for suggesting.
Try below trick:
In Android Studio:
Files -> Invalidate Caches / Restart
Please let me know if this solved your issue.
Once i had this issue, and my issue was resolved when i tried changing theme in xml layout.
Also check your theme in android manifest and styles. It can be an theme error.
I am attaching an image for your convenience.

Android Studio Beta 1.2 issue formatting xml-layout

Recently I’ve upgraded from Android Studio 1 to Android Studio Beta 1.2.
And among other issues, it seems that the shortcut (Option + Command + L) for formatting the xml-layouts it doesn’t reorganice code any more.
In the previous version of Android Studio, if you had something like this:
<RelativeLayout
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp"
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
After formatting you got the next result:
<RelativeLayout
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp">
But now I just get this message: “No lines changed. Code is already properly formatted”
Is there any kind of configuration that I’m missing it?
Thanks!
Try Ctrl+Shift+Alt+L, you should have a dialog where you can tick "Rearrange".

XML error - Doing Google Android NDK Lesson 1

The Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_weight = "1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:id="#+id/bSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
The error message:
BUILD FAILED
C:\My First App\res\layout\activity_main.xml:7: Unexpected element "{}LinearLayout" {antlib:org.apache.tools.ant}LinearLayout
The code is almost exactly the same as the code on the Android website and it's really frustrating that I can't seem to get it to work. Is the problem in the code, or is it on my side? I am using Eclipse
I was getting the same error. I was using Indigo in Ubuntu 12.04, and no matter what libraries I got or eclipse plugins I used it was always there.
What worked for me was re-downloading and reinstalling the Android SDK (probably not necessary in your case), and downloading Eclipse Classic (Juno) from the Eclipse website rather than using the Indigo package that was in the repos. The lesson said Classic was recommended anyway, so whatever, I'm just happy it works now.
If you are using Windows, I'd still suggest downloading the most recent Classic version, but otherwise I can't be of help there.

Categories

Resources