0

I tried to make my Android app in Kotlin with Holo theme My code: activity_main.xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp">

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter your name:"
        android:textSize="18sp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textColor="@android:color/black"/>

    <EditText
        android:id="@+id/nameEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Name"
        android:layout_below="@id/label"
        android:layout_marginTop="16dp"
        android:layout_centerHorizontal="true"/>

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login"
        android:layout_below="@id/nameEditText"
        android:layout_marginTop="16dp"
        android:layout_centerHorizontal="true"/>

    <TextView
        android:id="@+id/forgotPasswordTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Forgot password?"
        android:textColor="@android:color/holo_blue_light"
        android:layout_below="@id/loginButton"
        android:layout_marginTop="16dp"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>

MainActivity.kt:

package resichat.messenger

import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val nameEditText: EditText = findViewById(R.id.nameEditText)
        val loginButton: Button = findViewById(R.id.loginButton)
        val forgotPasswordTextView: TextView = findViewById(R.id.forgotPasswordTextView)

        loginButton.setOnClickListener {
            val name = nameEditText.text.toString()
            if (name.isEmpty()) {
                Toast.makeText(this, "Please enter your name", Toast.LENGTH_SHORT).show()
            } else {
                // Perform login action
                Toast.makeText(this, "Welcome, $name", Toast.LENGTH_SHORT).show()
            }
        }

        forgotPasswordTextView.setOnClickListener {
            // Handle forgot password action
            Toast.makeText(this, "Forgot password clicked", Toast.LENGTH_SHORT).show()
        }
    }
}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.Holo.Light">
        <activity
            android:name=".MainActivity"
            android:exported="true" > <!-- или false, в зависимости от твоих нужд -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

When building, an error occurs:

Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [com.google.android.material:material:1.12.0] C:\Users\antidote\.gradle\caches\8.13\transforms\df0ae31f5849b8ddc2231abbdf851cf6\transformed\material-1.12.0\AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
        or increase this project's minSdk version to at least 19,
        or use tools:overrideLibrary="com.google.android.material" to force usage (may lead to runtime failures)

although the Preview shows that the theme is loading priview How can I solve the problem without updating the theme to Material?

If I update min API in Gradle, then yes, the problem will go away, but I need support for older devices (I really need Android 4.0 support)

1
  • If you need Android 4 support don't use a library that was released in 2024 and requires API Level 19 / Android 4.4 at minimum. And I would recommend to use an older version of Android Studio. Commented Jul 17 at 8:45

1 Answer 1

0

Completely agreed with @Robert. Don't use a library which require minimum API level 19 if you wants support for API 16.

As suggested in the error itself you can use
tools:overrideLibrary="com.google.android.material" to force usage (may lead to runtime failures)

However,
tools:overrideLibrary should be used with extreme caution and only as a last resort if you understand the risks and have thoroughly tested that your app does not call any incompatible APIs from the library on older devices.

      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            package="YOUR_PACKAGE_NAME">

            <uses-sdk
                android:minSdkVersion="16"
                android:targetSdkVersion="YOUR_TARGET_SDK_VERSION"
                tools:overrideLibrary="com.google.android.material" />
            
            <application
                ...>
                ...
            </application>
        </manifest>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.