Can't print log messages from JNI with Android Studio

后端 未结 3 1235
有刺的猬
有刺的猬 2021-01-12 06:13

Error I\'m getting:

error: undefined reference to \'__android_log_print\'

I\'ve already added this line to my .cpp file:

相关标签:
3条回答
  • 2021-01-12 06:29

    I use Gradle 2.5 with Android Studio 1.4.1 and it works for me with this syntax:

    ldLibs += "log"

    The model build.gradle should be something similar:

    
    apply plugin: 'com.android.model.application'
    
        model{
            android {
                compileSdkVersion = 23
                buildToolsVersion = "23.0.1"
    
                defaultConfig.with {
                    applicationId = "com.local.some.project"
                    minSdkVersion.apiLevel = 17
                    targetSdkVersion.apiLevel = 23
                    versionCode = 1
                    versionName = "1.0"
                }
            }
    
            android.buildTypes {
                release {
                    minifyEnabled = false
                    proguardFiles += file('proguard-rules.pro')
                }
            }
    
            android.ndk {
                moduleName = "MyModel"
                ldLibs += "log"
            }
    
            compileOptions.with {
                sourceCompatibility = JavaVersion.VERSION_1_7
                targetCompatibility = JavaVersion.VERSION_1_7
            }
        }
    
        dependencies {
            compile fileTree(include: ['*.jar'], dir: 'libs')
            compile 'com.android.support:appcompat-v7:23.0.1'
            compile files('libs/some3rdParty.jar')
        }
        
    0 讨论(0)
  • 2021-01-12 06:38

    ADD this in Your android.mk file

    LOCAL_LDLIBS := -llog -ljnigraphics

    0 讨论(0)
  • 2021-01-12 06:47

    It seems that using Gradle + Android Studio the Android.mk file is ignored.

    As explained here, try adding the following directive to your build.gradle:

    android {
        defaultConfig {
            ndk {
                moduleName "modulename"
                ldLibs "log"
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题