I'm trying to build my first app in Android Studio 4.1.2. I have created a new project (Empty project) with default "Hello world!" Main Activity.
When trying to validate the activity_main.xml I get the following errors:
Error:External resource http://schemas.android.com/apk/res/android is not registered C:\AndroidStudioProjects\MyApp\app\src\main\res\layout\activity_main.xml
Error:(7, 35) cvc-elt.1.a: Cannot find the declaration of element 'androidx.constraintlayout.widget.ConstraintLayout'.
Error:Premature end of file.
I have already tried the following:
Reinstall Android studio
Sync Project with Gradle Files
Invalidate Caches / Restart
build.gradle also has the line implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
I can run the application in emulator or actual device but apparently the validation error prevents me to refer to the layout elements from Kotlin code.
Any ideas how to fix this error?
Here's the activity_main.xml in code:
<?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:id="#+id/layoutOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textMyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
androidx.constraintlayout.widget.ConstraintLayout
Change this to
RelativeLayout
Related
I am currently learning Android Studio and ran into an issue in the activity_main.xml, where i cannot view then buttons, text and etc. (See image Link).
Link to Andoird Studio screenshot
I am also getting following error:
The following classes could not be instantiated:
- androidx.constraintlayout.widget.ConstraintLayout (Open Class, Show Exception, Clear Cache)
Exception Details java.lang.ClassNotFoundException: androidx.constraintlayout.core.widgets.analyzer.BasicMeasure$Measurer Copy stack to clipboard
I did try to build the project and update dependencies without success.
The XML code is:
<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"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="#tools:sample/cities" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="393dp"
android:layout_marginRight="393dp"
android:layout_marginBottom="657dp"
android:text="#string/button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
And I have following implementation:
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
Instead of the added dependency for constraint layout use the below:
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
i'm trying to build my app
<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"
tools:context=".ChatForm">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<argument
android:name="numQuestions"
app:argType="integer"/>
<argument
android:name="numCorrect"
app:argType="integer"/>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
But the problem is I am getting an error during compile as below:
C:\Users\ASUS\AndroidStudioProjects\AplikasiForensik\app\src\main\res\layout\activity_chat_form.xml:29: AAPT: error: attribute argType (aka com.example.aplikasiforensik:argType) not found.
It seems to be that you need to add dependencies for safe Args, I had the same problem when compiling, but after adding the dependencies it just compiles fine, but the linter of the android studio not recognise "app:argtype" as valid.
//In top level gradle
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.3.1"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
//In app level gradle
apply plugin: "androidx.navigation.safeargs.kotlin"
then resync the gradle files and run your app, hope it works for you to!
safe Args page
I started using Android Studio 2.2 and ConstraintLayout today, but I'm having some issues with the rendering. When using Blueprint Mode everything appears fine. When using Design Mode, the objects are stuck at the top left corner all mashed together.
Android Studio warning: onMeasure error
java.lang.NoSuchMethodError: android.support.constraint.solver.widgets.ConstraintWidget.immediateConnect(Landroid/support/constraint/solver/widgets/ConstraintAnchor$Type;Landroid/support/constraint/solver/widgets/ConstraintWidget;Landroid/support/constraint/solver/widgets/ConstraintAnchor$Type;II)V
at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:517)
at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:433)
at android.support.constraint.ConstraintLayout.onMeasure_Original(ConstraintLayout.java:728)
at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java)
at android.view.View.measure(View.java:19731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19731)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19731)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:545)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:342)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$72(RenderTask.java:659)
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)
The dependency:
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
Is this an unsolvable error in Android Studio or is there something that is solvable? SDK is updated.
EDIT
XML file:
<?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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="#drawable/about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView6"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="16dp" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView33"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/imageView6"
android:layout_marginLeft="16dp" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView34"
app:layout_constraintRight_toRightOf="#+id/textView33"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView33" />
</android.support.constraint.ConstraintLayout>
as mentioned here
Constraint Layout Alpha8 release notes
Note: due to API change, you might have to restart Android Studio 2.2 after upgrading to alpha 8 for layout preview to work.
so From the menu bar, select file and choose invalidate caches / restart
I had that problem after update
implementation 'androidx.constraintlayout:constraintlayout:1.1.3
to
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
downgrade back to 1.1.3 resolve problem
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.yossikally.hello.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<!--<android.support.design.widget.FloatingActionButton-->
<!--android:id="#+id/fab"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="bottom|end"-->
<!--android:layout_margin="#dimen/fab_margin"-->
<!--android:src="#android:drawable/ic_dialog_email" />-->
</android.support.design.widget.CoordinatorLayout>
I built the simplest hello world project.
In the xml design pane I get what's in the picture
Tried to change themes and change version. Get the same
please add to your App gradle file Android Design Support Library:
compile 'com.android.support:design:23.+'
I want to include a layout of .axml file in another .axml using xamarin android but,
when i use <include> it doesn't show any thing. What is the equivalent to <include> of android in mono android just like the link below:
android reuse layouts
There is no difference between Xamarin.Android (Mono for Android) or native Android's XML files. The axml extension is purely to trigger the code completion in VS and Xamarin Studio. Android does not care what extension the files have.
So let me allow to show a sample showing both the <merge> and <include> tags:
progress_with_text.axml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="Loading..."
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/lblLoading"
android:layout_marginLeft="180dp"
android:layout_marginTop="240dp"/>
<ProgressBar
android:id="#+id/progBar"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="230dp"/>
</merge>
main.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
layout="#layout/progress_with_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
This works perfectly fine!