Android Question XmlLayoutBuilder - ConstraintLayout

moster67

Expert
Licensed User
Longtime User
As requested, I am re-posting my post from here as a question.

I was trying to load an xml-file using the new ConstraintLayout but I got an error while the R.file was generated:

B4X:
B4A version: 6.30
Parsing code.    (0.00s)
Compiling code.    (0.07s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Generating R file.    Error
res\layout\layxml.xml:10: error: No resource identifier found for attribute 'layout_constraintTop_toTopOf' in package 'b4a.example'
res\layout\layxml.xml:10: error: No resource identifier found for attribute 'layout_constraintBottom_toBottomOf' in package 'b4a.example'
res\layout\layxml.xml:10: error: No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'b4a.example'
res\layout\layxml.xml:10: error: No resource identifier found for attribute 'layout_constraintRight_toRightOf' in package 'b4a.example'

This is the xml-file:

B4X:
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.mikael.myapplication.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="16dp"
        android:layout_marginStart="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="16dp"
        android:layout_marginEnd="16dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginRight="16dp"
        android:id="@+id/txtbox1" />
</android.support.constraint.ConstraintLayout>

I noted that my project in Android Studio was using two dependencies:
-appcompat-v7
-constraint-layout
as can be shown here:

B4X:
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
}

I tried to add the following two attributes in my B4A-project:

B4X:
#AdditionalJar: com.android.support:appcompat-v7
#AdditionalJar: constraint-layout
but it did not work.
Note: I tried first with 'com.android.support.constraint:constraint-layout' but it gives the error: 'Maven artifact not found: org.testng/testng' while using only 'constraint-layout' does not trigger any error.

Am I doing something wrong or is it simply B4A and the XMLLayoutBuilder library which cannot handle this new layout?
 

Attachments

  • Constraint.zip
    7.3 KB · Views: 537

Erel

B4X founder
Staff member
Licensed User
Longtime User
Remove the reference to the testing framework by editing this file:
android-sdk-windows\extras\android\m2repository\com\android\support\constraint\constraint-layout-solver\1.0.0-alpha1\constraint-layout-solver-1.0.0-alpha1.pom

Now you will be able to add:
B4X:
#AdditionalJar: com.android.support.constraint:constraint-layout

There will be a different error which I guess is related to an incorrect XML layout file.

Overall I think that it is better to use B4A designer to implement your layout instead of "fighting the system".
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thanks. I will try as you suggested.
Overall I think that it is better to use B4A designer to implement your layout instead of "fighting the system".
It's true and this is the reason why we are using B4A but I guess it was just my curiosity who drove me to test it out...
 
Upvote 0
Top