Android Studio dependency(?) problem while trying to learn JUnit testing - Beginner here - TagMerge
2Android Studio dependency(?) problem while trying to learn JUnit testing - Beginner hereAndroid Studio dependency(?) problem while trying to learn JUnit testing - Beginner here

Android Studio dependency(?) problem while trying to learn JUnit testing - Beginner here

Asked 1 years ago
0
2 answers

Such as error said, a dependancy (here: androidx.appcompat:appcompat:1.4.1) require a minimum SDK of 31.

Your project seems to require a minimum of SDK 30.

The conflict between both is created because of device with SDK 30. Such as they will run with 30, the dependancy could run, because it's in a newer version.

The opposite is allowed thanks to backwards compatibility. That's why some people make API with very low SDK, it's to prevent those type of issue.

To solve this, you can:

  1. Stay on SDK 30, and find an older version that require SDK 30 instead of 31. The 1.4.0 seems to do it, so you can use androidx.appcompat:appcompat:1.4.0.
  2. Use at least SDK 31 as minimum compile SDK. This will break some device support, but also allow you to use some new features.

Source: link

0

android {
    packagingOptions {
    exclude 'LICENSE.txt'
    }
}
dependencies {
    // Unit testing dependencies
    testCompile 'junit:junit:4.12'
    // Set this dependency if you want to use the Hamcrest matcher library
    testCompile 'org.hamcrest:hamcrest-library:1.3'
    // more stuff, e.g., Mockito
}
android {
  // ...
  testOptions {
    unitTests.returnDefaultValues = true
  }
}
dependencies {
    // Unit testing dependencies
    testImplementation 'junit:junit:4.12'
}
package com.vogella.android.temperature.test;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.vogella.android.temperature.ConverterUtil;

public class ConverterUtilTest {

    @Test
    public void testConvertFahrenheitToCelsius() {
        float actual = ConverterUtil.convertCelsiusToFahrenheit(100);
        // expected value is 212
        float expected = 212;
        // use this method because float is not precise
        assertEquals("Conversion from celsius to fahrenheit failed", expected, actual, 0.001);
    }

    @Test
    public void testConvertCelsiusToFahrenheit() {
        float actual = ConverterUtil.convertFahrenheitToCelsius(212);
        // expected value is 100
        float expected = 100;
        // use this method because float is not precise
        assertEquals("Conversion from celsius to fahrenheit failed", expected, actual, 0.001);
    }

}

Source: link

Recent Questions on android

    Programming Languages