티스토리 뷰

카테고리 없음

multiple so

newpolaris 2020. 10. 16. 17:47

https://stackoverflow.com/questions/46918887/how-to-create-an-jni-android-studio-project-with-multiple-static-libs

최상위 cmakelists.txt 에 아래와 같이 설정 후,

add_subdirectory(hello1)
add_subdirectory(hello2)

build.gradle 을 설정해주면,

    externalNativeBuild {

        cmake {
            version '3.10.2'
            path 'src/main/cpp/CMakeLists.txt'
        }

    }

최상위 cmakelists.txt는 목록에 보이지 않지만,

so 까지 잘 넣어준다

package com.example.jnitest

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var hello1 : String? = nativeHello1()
        var hello2 : String? = nativeHello2()
    }

    external fun nativeHello1(): String?
    external fun nativeHello2(): String?

    companion object {
        /*
         * this is used to load the 'hello-jni' library on application
         * startup. The library has already been unpacked into
         * /data/data/com.example.hellojni/lib/libhello-jni.so
         * at the installation time by the package manager.
         */
        init {
            System.loadLibrary("ndk_hello1")
            System.loadLibrary("ndk_hello2")
        }
    }
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크