howardpang / androidNativeBundle

a gradle plugin that support publish c/c++ headers to 'aar' and depend those 'aar'
Apache License 2.0
71 stars 14 forks source link

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

Closed marandaneto closed 4 years ago

marandaneto commented 4 years ago

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: https://github.com/getsentry/sentry-android/pull/161/

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

howardpang commented 4 years ago

may i see the build.gradle in app?

发自我的iPhone

在 2019年11月23日,上午2:11,Manoel Aranda Neto notifications@github.com 写道:



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#161https://github.com/getsentry/sentry-android/pull/161

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/howardpang/androidNativeBundle/issues/1?email_source=notifications&email_token=ABHINMYHF6HPL5VY734J5K3QVAOFJA5CNFSM4JQUGX72YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4H3OSR5A, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABHINM2YB34RSZUGBDXTO4TQVAOFJANCNFSM4JQUGX7Q.

marandaneto commented 4 years ago

sure. here is the gradle https://github.com/getsentry/sentry-android/blob/feat/ndk_link/sentry-sample/build.gradle.kts and here is the cmakelist https://github.com/getsentry/sentry-android/blob/feat/ndk_link/sentry-sample/CMakeLists.txt

trying to import sentry.h here https://github.com/getsentry/sentry-android/blob/feat/ndk_link/sentry-sample/src/main/cpp/native-sample.cpp

thanks a lot.

howardpang commented 4 years ago

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)

marandaneto commented 4 years ago

@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.

marandaneto commented 4 years ago

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.

howardpang commented 4 years ago

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} )
marandaneto commented 4 years ago

perfect will give it a try, thanks :)

marandaneto commented 4 years ago

it worked like a charm, thank you :)