Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build v4 support library from source

I'm trying to build the v4 support library from source sice I modified a portion of the library. I'm trying to do this on ubuntu 13.10 with gradle. I followed the instructions in this answer, but now I'm stuck. I used gradle 1.10 with ubuntu since when I tried to build it on windows, it said windows wasn't supported and on ubuntu with gradle 2.4 it said gradle 1.10 was the version that was supported. When I try building with

gradle clean jar --stacktrace

I keep getting an IllegalStateException: llvm-rs-cc is missing, this is a portion of the the stack trace which I keep getting

Caused by: java.lang.IllegalStateException: llvm-rs-cc is missing
    at com.android.builder.AndroidBuilder.compileAllRenderscriptFiles(AndroidBuilder.java:1281)
    at com.android.builder.AndroidBuilder$compileAllRenderscriptFiles.call(Unknown Source)
    at com.android.build.gradle.tasks.RenderscriptCompile.taskAction(RenderscriptCompile.groovy:99)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)

The whole stacktrace is here

I tried looking through the source code at AndroidBuilder.java and that hasn't shed any light. I even tried copying the said llvm-rs-cc file from android-sdk-linux/build-tools to as many folders as I could. I've added the the path to the llvm-rs-cc binary to my path as like the comment in BuildToolInfo.java and also the path to build-tools, tools, and platform-tools which I believe I downloaded using the android sdk manager. I confirmed that the path were added using the printenv command after restarting.

What am I doing wrong?

like image 829
Olumide Avatar asked Jun 21 '15 08:06

Olumide


People also ask

How do I add the v7 Appcompat support library to my project?

In the Properties window, select the "Android" properties group at left and locate the Library properties at right. Select /path/to/appcompat/ and Click Remove. Click Add to open the Project Selection dialog. From the list of available library projects, select v7 appcompat library and click OK.

What is AndroidX support library?

AndroidX is the open-source project that the Android team uses to develop, test, package, version and release libraries within Jetpack. AndroidX is a major improvement to the original Android Support Library.

Should you use legacy Android support libraries?

We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well. So all Android apps should now aim to use AndroidX, instead of the old support library.


1 Answers

It turns out that that that I needed to edit the local.properties file in plaform/frameworks/support to add the sdk directory, i.e

sdk.dir=/path/to/android-sdk-linux/

Adding this actually made the whole llvm-rs-cc shenenigans disappear but... there's more

The stackoverflow answer that I was following said to use this command

platform\frameworks\support\v4\gradle clean jar

which I interpreted to mean navigate to the v4 directory then call gradle with

gradle clean jar

Here are the *complete steps I followed in case anybody wants to built the support library also.

  1. First, follow the instructions in this answer:

You need to checkout additional repositories from https://android.googlesource.com:

  • platform/frameworks/support
  • platform/prebuilts/gradle-plugin
  • platform/prebuilts/maven_repo/android
  • platform/prebuilts/sdk
  • platform/prebuilts/tools

Please, keep the directory structure as in android repository.

  1. Install the packages lib32stdc++6 and lib32z1, I used apt-get

    sudo apt-get install lib32stdc++6

    sudo apt-get install lib32z1

  2. Download the android sdk from the android developer website here

  3. Unpack the archive to any location then navigate to it then to tools\

  4. run ./android this should lainch the sdk manager then download these packafes if they're not already downloaded

    • All android api from api 4 to api 22 (You may need to show obsolete packages).
    • Build tools 19.01 (You may need to show obsolete packages) and the most recent build tools
    • Most recent Platform tools
    • Most recent SDK tools

Normally this should be sufficient to build the support library with gradle, but it turns out that the jar file in the git repository for api 22 is actually not up to date as it doesn't contain the new AccessibilityInfo methods that were added in api 22, yes I decompiled it to be sure. So a few more steps.

  1. Replace the andoid.jar file in platform/prebuilts/sdk/current that you downloaded from the git repository with the one from android-sdk-linux/platforms/android-22/

We're almost done here but two more issues. If you try to build the library now there'll be two compiltion errors in Fragment.java and in FragmentActivity.java feel free to fix these however you like, since I'm not sure how correct my fix for these were.

To fix these, in Fragment.java on line #935 I added a cast so

result.setFactory(mChildFragmentManager.getLayoutInflaterFactory());

became this

result.setFactory((LayoutInflater.Factory)mChildFragmentManager.getLayoutInflaterFactory());

For the other fix, in FragmentActivity.java on line #299 I replaced

final View v = mFragments.onCreateView(name, context, attrs);

with this

final View v = mFragments.onCreateView(null, name, context, attrs);

The reason for adding the null there was because in the previous versions the first parameter, which is View parent didn't exist and in the onCrateView method parent was declared and initialized to null.

The resulting jar file can be found in platform/out/host/gradle/frameworks/support/support-v4/build/libs/ *Some steps may be missing, as this process took me a long time, and I may have forgotten some things I did.

like image 57
Olumide Avatar answered Oct 11 '22 02:10

Olumide