Search code examples
android-studiokotlindependencies

Offline layout dependencies in Android Studio


I'm new to Android Studio and after installing the program, I noticed that "Hello World" in the design layout only appears when when my computer is online, I guess it's because of the the dependencies in the activity_main.xml file.

<?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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

The design layout loads only when my computer is online, and when it's offline, the design layout is blank, I see a bunch of class errors and project errors when it's offline such as:

Class referenced in the layout file, androidx.constraintlayout.widget.ConstraintLayout, was not found in the project or the libraries

Cannot resolve class androidx.constraintlayout.widget.ConstraintLayout

Please how do I download the dependencies offline and rewrite the http dependencies in the activity_main.xml file, so I can code when I'm offline. Thanks


Solution

  • Add Bewlow Dependency in your build.gradle File in the dependencies block

     implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    
    • Like Below

    enter image description here

    • And Use it in XML

    enter image description here