NDK error problem analysis plan (1)

  • Foreword:
    • Prepare to practice the Ffmpeg framework systematically. Before running the old demo on the computer, I encountered two problems during the operation. These two problems are very common, so I will simply record them here.

1. Question 1 -couldn't find "libxxx-lib.so"

Process: com.xxx.xxxx, PID: 20866
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.xxx.xxxxx-EGmEBSamMJX987Fr07EMuA==/base.apk"],
nativeLibraryDirectories=[/data/app/com.xxx.xxxxx-EGmEBSamMJX987Fr07EMuA==/lib/arm64, 
/system/lib64, /hw_product/lib64, /system/product/lib64, /prets/lib64]]] couldn't find "libnative-lib.so"
  • Cannot find xxx.so library
  • Idea analysis
    • 1. First eliminate the cache problem, clear it and try again, confirm that the problem exists, and continue to step 2;

    • 2. Check the app->build->outputs->debug->app-debug.apk file, double-click to see if there is a corresponding so file generated under the lib folder. If not, continue to step 3;
      insert image description here

    • 3. Check the build.gradle file of the module to see if the configuration similar to the following has been added. xxx1, xxx2, and xxx3 indicate the CPU type of the Android device (such as: arm64-v8a, armeabi-v7a, x86_64, x86, etc.)

      ndk {
              
              
      	abiFilters  "xxx1","xxx2","xxx3"
      }
      

      After adding it, compare it with the above picture. The so file has been generated and
      insert image description here
      the so file has not been compiled into the apk. The reason is more than one of step 3. Here is just an analysis method (step 1 cannot be ignored, and I personally think it is very important). If It is determined that the so file is not compiled into the apk, and you can search further (there are many online articles) to find out other reasons that cause the so not to be compiled into the apk.

2. Question 2 - Native layer code error

  • 2.1. The error message is as follows
    insert image description here
  • 2.2. The idea of ​​locating the error code
    • 2.2.1. With the help of ndk tools, as shown below
      insert image description here
  • 2.2.2. Find the folder of the so file shown in the figure below, such as: C:xxx\app\build\intermediates\cmake\debug\obj\armeabi-v7a
    insert image description here
  • 2.2.3. Enter the command to locate the error message
#打开命令行窗口,进入2.2.1中提到的文件夹目录,执行模板命令
aarch64-linux-android-addr2line -e C:xxx\app\build\intermediates\cmake\debug\obj\armeabi-v7a.so 000bca13
  • Among them, 000bca13 is input according to the prompt in 2.1. Take backtrace: as the starting point to check down. Both #00 and #01 are not related to the project source code, while #03 is related. Here, it corresponds to 000bca13. After finding it Just follow the template command above to make changes.
  • Locate the error message in line 28 of the C:xxx\app\src\main\cpp\native-lib.cpp file, and modify it according to the actual situation.
    insert image description here

Guess you like

Origin blog.csdn.net/itTalmud/article/details/126089227