Public Maven JAR artifact with stubs for android.os.Build and android.util.Log

84 Views Asked by At

I develop a Java library that runs on the JVM as well as on Android. On Android, I use the classes android.os.Build and android.util.Log. Currently, I compile against com.google.android:android:4.1.1.4, which is very outdated.

Unfortunately, there are no newer version of the Android artifact in the Central Maven repository. As I know, Google moved to its own Maven repository: https://maven.google.com/.

However, I cannot find there any Maven artifact that contains stubs for android.os.Build and android.util.Log. Where can I find a maintained Maven artifact with stubs for both classes?

2

There are 2 best solutions below

2
VonC On BEST ANSWER

You could try org.robolectric/android-all, from robolectric.org, a framework that allows you to run Android tests directly on the JVM. It included stubs for many Android classes.

<dependency>
    <groupId>org.robolectric</groupId>
    <artifactId>android-all</artifactId>
    <version>14-robolectric-10818077</version> <!-- Check for the latest version -->
    <scope>test</scope>
</dependency>

Remember, Robolectric is primarily intended for testing, so it is included with the test scope. If you need these stubs for non-testing purposes, you may need to adjust the scope or find an alternative solution.

Note that, for Android development, it is generally recommended to use Android Studio and its integrated Gradle system, which has direct access to Android's Maven repository. That approach would provide you with the most up-to-date and compatible libraries for Android development.

0
Rahul Rokade On

Please Try to this step:

android.os.Build and android.util.Log

below step first follows

  1. Open android Studio -> File -> invalid and cache restart

  2. Build -> Clean Project and after that rebuild project

  3. File -> Setting -> Search on Gradle and set Java17 amazon

  4. File -> Project Structure -> Project -> Android Gradle plugin Version 8.1.1 and gradle version 8.0

  5. then Go to the Setting.Gradles file

    repositories { google() mavenCentral() gradlePluginPortal() }

  6. gradle properties open file ->

    android.useAndroidX=true, android.nonTransitiveRClass=true

  7. Tool option clicked -> AGP Upgrade assistant -> Select 8.1.2 then Run selected step and Refress.

  8. Build.gradle(module.app) open file and API level 34.

namespace = "com.flora.ordertracker"

compileSdk = 34

minSdk = 24

targetSdk = 34

versionCode = 1