Search code examples
androidandroid-source

How to use the sdk which is built by modifying the aosp framework code?


I am new in Android Open Source Project (ASOP). I have been trying to make a custom android version with my own changes for research purposes. I have changed some code in the framework in Acitivty.java class. Added a custom function of mine like below:

 public final void requestPermissions(@NonNull String[] permissions, int requestCode, String permReason, String dataScope) {
    
    Log.i("PermissionTracker", "Rashed Tracking Permission Manager having requestCode"+Integer.toString(requestCode));
Log.i("PermissionReason", "I am asking permission because of "+permReason);
Log.i("PermissionReason", "The data scope would be "+dataScope);

/*
        Rashed edit end April 23, 2021
    */
    if (requestCode < 0) {
        throw new IllegalArgumentException("requestCode should be >= 0");
    }
    if (mHasCurrentPermissionsRequest) {
        Log.w(TAG, "Can request only one set of permissions at a time");
        // Dispatch the callback with empty arrays which means a cancellation.
        onRequestPermissionsResult(requestCode, new String[0], new int[0]);
        return;
    }
    Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions);
    startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null);
    mHasCurrentPermissionsRequest = true;
}

After that, I have done some other changes as well where I mostly added some log messages and got the output. I built the directory using the following commands and it worked:

. build/envsetup.sh
lunch sdk_phone_x86 sdk-eng
make -j16 sdk

My target was to generate the custom sdk as well which can be used in Android studio as well where I am working in another app. I would like to call my modified function from the app in the Android Studio. I have successfully updated the Android Studio sdk directory. But the problem is that, I cannot see my modified code in the Android Studio. Can anyone help me with that? Thanks for your kind suggestion in advance.


Solution

  • If your modification is part of android frameworks, you need to copy modified jar from out/target/common/obj/JAVA_LIBRARIES/framework_intermediates(for ex)/classes.jar in your Android Studio project.

    You need also to modify top-level gradle build to add :

    allprojects {
        repositories {
            jcenter()
        }
        gradle.projectsEvaluated {
            tasks.withType(JavaCompile) {
                options.compilerArgs << '-Xbootclasspath/p:app/src/main/lib/framework.jar'
            }
        }