Search code examples
androidandroid-source

Android.mk file for using UpdateEngine (SystemApi)


I found an example of using OTA updates. But i need to use android.os.UpdateEngine

This is SystemApi, and i found this question on StackOverFlow, where answer is wrote to android.mk file LOCAL_SDK_VERSION := system_current

I never worked with android.mk files before, so i created it and put to app/android.mk

This is all that i have in mine android.mk file:

LOCAL_PATH := $(call my-dir)
LOCAL_SDK_VERSION := system_current

Also i add this to build.gradle file (i dont use NDK in my app, but i dont know another ways to use android.mk file)

sourceSets.main {
        jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jniLibs
        jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
    }
externalNativeBuild {
        ndkBuild {
            path 'Android.mk'
        }
    }

But anyway, when i writing import android.os.UpdateEngine i'm getting Cannot resolve symbol "UpdateEngine"

I was trying to search on Stack, Google, but cannot find solution.


Solution

  • I got it working without a makefile or the NDK by using the modified android.jar file from this repo: https://github.com/anggrayudi/android-hidden-api

    Download the appropriate android.jar file and place it at app/libs-sdk in your project.

    Add the following dependency to your app build.gradle file:

    compileOnly fileTree(include: ['*.jar'], dir: 'libs-sdk')
    

    In the top level build.gradle file add the following code to make Android Studio use the modified android.jar.

    allprojects {
        gradle.projectsEvaluated {
            tasks.withType(JavaCompile) {
                options.compilerArgs.add('-Xbootclasspath/p:/android.jar')
            }
        }
    }
    

    After these steps I could access the android.os.UpdateEngine class from my project. The only issue this does not fix is accessing some SystemApi methods (not classes) such as RecoverySystem#verifyPackageCompatibility.