zoukankan      html  css  js  c++  java
  • Android NDK调试方式之一: adb logcat

    查看程序执行过程中所打印的log信息,用于辅助调试排除代码错误。

    一、采用NDK安装包下Samples/hello-jni工程做实验

    1)修改jni/hello-jni.c文件

    #include <android/log.h>
    
    __android_log_print(ANDROID_LOG_INFO, "HelloJniTag", "The value is %d", 1000);

    2)修改jni/Android.mk文件

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LOCAL_MODULE    := hello-jni
    LOCAL_SRC_FILES := hello-jni.c
    LOCAL_LDLIBS    := -llog
    
    include $(BUILD_SHARED_LIBRARY)

    3)使用eclipse打开当前项目,运行测试,Debug As...

    4)在eclipse的logcat监控窗口观察日志信息

    二、NDK开发的一般步骤

    1)启动eclipse创建android application工程;

    2)创建activity应用类(可仿照HelloJni中HelloJni.java);

    3)在activity应用类中加入native函数声明及调用;

         public native String  stringFromJNI();
    
        /* This is another native method declaration that is *not*
         * implemented by 'hello-jni'. This is simply to show that
         * you can declare as many native methods in your Java code
         * as you want, their implementation is searched in the
         * currently loaded native libraries only the first time
         * you call them.
         *
         * Trying to call this function will result in a
         * java.lang.UnsatisfiedLinkError exception !
         */
        public native String  unimplementedStringFromJNI();
    
        /* 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
         * installation time by the package manager.
         */
        static {
            System.loadLibrary("HelloJni1");
        }

    4)在命令行模式下使用javah生成jni头文件,并创建c或c++实现文件;

    javah -jni -d jni -cp bin/classes:Android-20.jar  com.example.hellojni.HelloJni
    

    5)在jni目录下创建Android.mk、Application.mk编辑脚本

    #Android.mk
    
    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LOCAL_MODULE    := hello-jni
    LOCAL_SRC_FILES := hello-jni.c
    LOCAL_LDLIBS    := -llog
    
    include $(BUILD_SHARED_LIBRARY)
    #Application.mk
    
    APP_ABI := all
    

    6)修改AndroidManifest.xml文件,仿照HelloJni添加工程启动的Activity配置项。

    7)eclipse启动Debug As...进行调试。

      

  • 相关阅读:
    jQuery 选择器:元素选择器、#id 选择器、.class 选择器
    jQuery 语法:文档就绪事件
    jQuery 安装:多种方法在网页中添加 jQuery
    jQuery 简介:什么事jQuery?为什么要学jQuery?
    SQL 快速参考:SQL语句语法
    SQL FORMAT() 函数:对字段的显示进行格式化
    Mybatis-Plus逻辑删除
    Mybatis-Plus中的ActiveRecord
    Mybatis-Plus使用Oracle的序列
    SpringBoot整合Mybatis-Plus
  • 原文地址:https://www.cnblogs.com/feika/p/4026637.html
Copyright © 2011-2022 走看看