howardpang / androidNativeBundle

a gradle plugin that support publish c/c++ headers to 'aar' and depend those 'aar'

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

native-aar.import is creating build/nativeLib with empty .mk files

marandaneto opened this issue · comments

Hey, I'm trying to use your export and import plugin, but I am having issues, not sure If I'm doing something wrong.

I have a module (android lib.) that compiles native code and it generates shared libraries .sos, so in the end, we have a fat .aar which contains the so files and the header, so it seems that the export plugin works just fine, thanks for that.

When my App. adds this .aar as a maven dependency (gradle implementation), the plugin import is not generating the build/nativeLib properly, we only see 2 empty files gradle.mk and tmp.mk.

the changes may have seen here:
getsentry/sentry-android#161

would be nice if you could point out what we are doing wrong, thanks a lot.

i didn't see the app have dependency for the sentry-android-ndk lib, here is your app dependencies

dependencies{
	implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

	implementation(project(":sentry-android"))

	implementation(Config.Libs.appCompat)

	// debugging purpose
	implementation(Config.Libs.timber)
	debugImplementation(Config.Libs.leakCanary)


	testImplementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
	testImplementation(Config.TestLibs.junit)
	androidTestImplementation(Config.TestLibs.espressoCore)
	androidTestImplementation(Config.TestLibs.androidxCore)
	androidTestImplementation(Config.TestLibs.androidxRunner)
	androidTestImplementation(Config.TestLibs.androidxJunit)
	androidTestUtil(Config.TestLibs.androidxOrchestrator)
}

you can try to publish your sentry-android-ndk module to maven local, and then add a dependency to app, like this implementation(com.xx.yy:sentry-android-ndk:1.0.0)

@howardpang ok I see, thanks for pointing it out.
actually our SDK is on jcenter and bintray already so no need to publish it on mavenLocal.

The thing is, sentry-android has the dependency of sentry-android-ndk so it's not need to depend on it directly. maybe that's the issue, does the plugin support transitive dependencies?
I'll try to add the dependency of sentry-android-ndk directly as well just to check if it works.

If the plugin doesn't support transitive dependencies, are you willing to implement it and count on me to help you out? I'd like to help :)

Thanks again.

actually it worked even as a transitive dependency, nice.
the thing is, it only works when the dependency is a maven dependency, but not a referenced module in the same project.
@howardpang do you have an idea why's that? thanks again.

the plugin is design to solve the app module depend a lib module that not in the same project with app. in your satuation, you can use another easy way to implement it. cmake support include other cmake project, here is example:

app CMakeList.txt

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

set(mylib_src_DIR ../myndklib/src/main/cpp) # another CMakeLists.txt dir

add_subdirectory(${mylib_src_DIR}

        myndklib/outputs # any name you want to set
        )


include_directories(${mylib_src_DIR})


add_library( # Sets the name of the library.
             nativeapp

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-app.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.


target_link_libraries( # Specifies the target library.
                       nativeapp
                       nativelib  #another library
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

lib CMakeLists.txt

 cmake_minimum_required(VERSION 3.4.1)


# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             nativelib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             mylib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.


find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
        nativelib


        # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

perfect will give it a try, thanks :)

it worked like a charm, thank you :)