JNI包装抱怨未定义的引用

Adrijan 07/27/2017. 0 answers, 39 views
android android c android-ndk android-ndk cmake jni

我正在尝试在Android应用中使用TagLib库。 据我所知,我必须为它编写一个JNI包装器。 我想尝试一些简单的东西 - 从标签中读取标题。

我在Java中编写了以下代码:

package developer.rogan.taglib;

import android.support.annotation.NonNull;
import android.util.Log;

public class TagJNI {

    private static final String TAG = "TagJNI";

    private String filename;
    private String title;

    public TagJNI(@NonNull String filename) {
        this.filename = filename;
    }

    public String getTitle() {
        Log.d(TAG, "getTitle, filename = " + filename);
        this.title = taglibGetTitle(filename);
        return title;
    }

    private native String taglibGetTitle(String filename);
} 

Android Studio然后让我选择自动生成本地代码中的函数(该文件称为tagjni.c)。 我添加了一些我自己的代码来添加功能:

#include #include "../../../../../../Development/C++/taglib-1.11.1/bindings/c/tag_c.h"

TagLib_File *file;
TagLib_Tag *tag;
char *title;

JNIEXPORT jstring JNICALL
Java_developer_rogan_taglib_TagJNI_taglibGetTitle(JNIEnv *env, jobject instance,
                                                  jstring filename_) {

    taglib_set_strings_unicode(JNI_FALSE);
    const char *filename = (*env)->GetStringUTFChars(env, filename_, 0);

    file = taglib_file_new(filename);
    tag = taglib_file_tag(file);
    title = taglib_tag_title(tag);
    taglib_file_free(file);
    (*env)->ReleaseStringUTFChars(env, filename_, filename);
    return (*env)->NewStringUTF(env, title);
} 

include语句也有一些问题。 我可以编写#include ,然后其他包含说它是未使用的。 但是,当我删除它时,没有任何变量被识别了。 当我将鼠标悬停在错误上时,我可以选择添加#include。

当我尝试运行该应用程序时,出现以下错误(以及一些更类似的错误): 未定义的引用'taglib_set_strings_unicode'

这是否意味着我所调用的函数无法找到? 我有很多问题,设置图书馆,并最终以某种方式工作。 在我开始编写JNI包装器时,Android Studio抱怨未包含在项目中的.c文件。 在查看NDK网页后,我想我必须创建一个根CMakeLists.txt,并引用其他两个(一个用于TagLib,一个用于JNI包装)。 我对C和CMakeLists知之甚少。 这就是我想到的:

cmake_minimum_required(VERSION 3.4.1)

add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
                  /home/adrijan/Development/C++/taglib-1.11.1
                  # Specifies the directory for the build outputs.
                  /home/adrijan/devel/tagtest/taglib/src/main/cpp )
add_library( taglib SHARED IMPORTED )

add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
                  /home/adrijan/devel/tagtest/taglib/src/main/jni
                  # Specifies the directory for the build outputs.
                  /home/adrijan/devel/tagtest/taglib ) 

TagLib已经包含一个CMakeLists,所以我只是指出它。 对于JNI包装器,我将CMakeLists.txt放在代码所在的目录中:

cmake_minimum_required(VERSION 3.4.1)

# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add.library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.

add_library( # Specifies the name of the library.
             jni-taglib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             tagjni.c )

# Specifies a path to native header files.
include_directories(tagjni.h) 

在我看来,我在这里错失了一些非常明显的东西。 我相信它必须按照我设置CMake的方式进行操作,但我无法弄清楚。

No Answers Yet


HighResolutionMusic.com - Download Hi-Res Songs

1 (G)I-DLE

POP/STARS flac

(G)I-DLE. 2018. Writer: Riot Music Team;Harloe.
2 Ariana Grande

​Thank U, Next flac

Ariana Grande. 2018. Writer: Crazy Mike;Scootie;Victoria Monét;Tayla Parx;TBHits;Ariana Grande.
3 Clean Bandit

Baby flac

Clean Bandit. 2018. Writer: Jack Patterson;Kamille;Jason Evigan;Matthew Knott;Marina;Luis Fonsi.
4 Imagine Dragons

Bad Liar flac

Imagine Dragons. 2018. Writer: Jorgen Odegard;Daniel Platzman;Ben McKee;Wayne Sermon;Aja Volkman;Dan Reynolds.
5 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
6 BTS

Waste It On Me flac

BTS. 2018. Writer: Steve Aoki;Jeff Halavacs;Ryan Ogren;Michael Gazzo;Nate Cyphert;Sean Foreman;RM.
7 Nicki Minaj

No Candle No Light flac

Nicki Minaj. 2018. Writer: Denisia “Blu June” Andrews;Kathryn Ostenberg;Brittany "Chi" Coney;Brian Lee;TJ Routon;Tushar Apte;ZAYN;Nicki Minaj.
8 Backstreet Boys

Chances flac

Backstreet Boys. 2018.
9 BlackPink

Kiss And Make Up flac

BlackPink. 2018. Writer: Soke;Kny Factory;Billboard;Chelcee Grimes;Teddy Park;Marc Vincent;Dua Lipa.
10 Little Mix

The Cure flac

Little Mix. 2018. Writer: Pete Kelleher;Camille Purcell;Tom Barnes;Ben Kohn.
11 Fitz And The Tantrums

HandClap flac

Fitz And The Tantrums. 2017. Writer: Fitz And The Tantrums;Eric Frederic;Sam Hollander.
12 Diplo

Close To Me flac

Diplo. 2018. Writer: Ellie Goulding;Savan Kotecha;Peter Svensson;Ilya;Swae Lee;Diplo.
13 The Chainsmokers

Beach House flac

The Chainsmokers. 2018. Writer: Andrew Taggart.
14 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
15 Kelly Clarkson

Never Enough flac

Kelly Clarkson. 2018. Writer: Benj Pasek;Justin Paul.
16 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
17 Frida Sundemo

Apologize flac

Frida Sundemo. 2018.
18 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
19 Imagine Dragons

Machine flac

Imagine Dragons. 2018. Writer: Wayne Sermon;Daniel Platzman;Dan Reynolds;Ben McKee;Alex Da Kid.
20 Billie Eilish

When The Party's Over flac

Billie Eilish. 2018. Writer: Billie Eilish;FINNEAS.

Related questions

Hot questions

Language

Popular Tags