Problems encountered by Android Studio in the Mp3Encoder in the Advanced Guide to Audio and Video Development

Increase the problems encountered in calling Native code in java in C++

Main error:

  1. In the directory of the corresponding class file, execute the following command to generate the JNI interface file
javah -jni com.phuket.tour.studio.Mp3Encoder

Javah has been abolished in the higher version of java, and it can be replaced by javac at present, using the following code to achieve

javac -h 保存的位置 ./Mp3Encoder.java
// ./Mp3Encoder.java是指在当前文件夹内的Mp3Encoder.java,如果不在当前文件夹内自行添加前面的文件名称
  1. Execute the ndk-build command to compile the dynamic so library.
    The problem here is huge. There are mainly 3 errors, which are all listed below. Starting from point 7, I have been looking for information for a long time to solve it.

My flow chart for each step:

First you need to install the packages you want to use

  1. ndk, there are a lot of information on the Internet, you can find it yourself
  2. Android API
  3. Android SDK PT 和 B U
  4. cmake
    insert image description here

insert image description here

1. Create a new project

insert image description here
insert image description here

2. The first and second steps in the book are to create a Java file and write a local method.

#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG, __VA_ARGS__)
        Java_com_phuket_tour_mp3encoder_MpeEncoder_encode(JNIEnv * env, jobject obj) {
    
    
    LOGI("encoder encode");
}

insert image description here
insert image description here

3. Create the jni folder

insert image description here
If there is no such option, create a file called jni directly in main, and tell build.gradle that this is in Android.
insert image description here

4. Generate JNI interface file

insert image description here
insert image description here
insert image description here

5. Create a cpp file in the cpp folder

insert image description here

6. Create the Android.mk file

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES = ./Mp3Encoder.cpp
LOCAL_LDLIBS :=-L$(SYSROOT)/usr/lib -llog
LOCAL_MODULE := jni
include $(BUILD_SHARED_LIBRARY)

insert image description here
An error will be reported later, and I will tell you one by one how to correct the error. First, let’s see what error is reported:
insert image description here
insert image description here

7. Three Questions

  1. Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-16

Solution:
This requires us to set up an Application.mk and set APP_PLATFORM

APP_STL := c++_static
APP_CPPFLAGS := -frtti -fexceptions -std=c++0x
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16

insert image description here
This error will not be reported after running ndk-build once.

  1. Android NDK: WARNING: APP_PLATFORM android-16 is higher than android:minSdkVersion 1 in D:/Android_app/mp3encoder2/app/src/main/AndroidManifest.xml. NDK binaries will not be compatible with devices older than android-16.

Solution:
insert image description here
insert image description here
This solves it, run it once
insert image description hereSource of the second solution: https://blog.csdn.net/jiao_mrswang/article/details/79820228

  1. make: *** No rule to make target ‘D:/Android_app/mp3encoder2/app/src/main/jni/./Mp3Encoder.cpp’, needed by ‘D:/Android_app/mp3encoder2/app/src/main/obj/local/armeabi-v7a/objs/jni/./Mp3
    Encoder.o’. Stop.

This problem is caused by the LOCAL_SRC_FILES = ./Mp3Encoder.cpp in this Android.mk
No rule to make target: the translation means that there is no rule to create a target, that is, this LOCAL_SRC_FILES is wrong. See the error and know it, Mp3Encoder. The address of cpp is wrong. In fact, it is in cpp, not in jni. I still don't know how to correct the error by modifying the value. I can only determine the target file of Android.mk by other methods:
first delete LOCAL_SRC_FILES = ./Mp3Encoder.cpp, and then as shown below:
insert image description here
insert image description here
Then run:
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/A_easy_learner/article/details/123296704