Someone
Someone

Reputation: 560

Assembly in android gradle experimental

Is there any way to include assembly code into a native library module in android studio.

Since this post says that you can only include *.C, *.CPP, *.c++, *.cc, *.cp, *.cpp, *.cxx files with srcDir i was wondering if there is maybe another solution or workaround to at least compile it with the native library.

I guess i could pre-compile the assembly code and then link it to my native module but with this i would have the problem that i have to rebuild it at every change and then rebuild the project itself which is not really a nice workflow so if you have any nicer ways let me know.

Upvotes: 0

Views: 433

Answers (1)

Miguel Benitez
Miguel Benitez

Reputation: 2322

First create include folder inside jni folder and libs folder inside the same folder. You also can create inside libs folder different folders for different chipsets (armeabi, mips,x86).

Copy your .h files inside include folder and your compile files (.a) in your libs folders

Then you have to change your build.gradle, adding a new repository inside the model

repositories {
    libs(PrebuiltLibraries) {
        libYourCLibrary{
            headers.srcDir "src/main/jni/include"
            binaries.withType(StaticLibraryBinary) {
                staticLibraryFile = file("src/main/jni/libs/${targetPlatform.getName()}/YOUR_C_LIBRARY.a")
            }
        }
    }
}

add dependencies of this repository inside the model

android.sources {
    main {
        jni {
            dependencies {
                library "libYourCLibrary" linkage "static"
            }
        }
    }
}

And finally Sync project with gradles files.

Upvotes: 1

Related Questions