0
0

More than 1 year has passed since last update.

vistaでandroid studio その22

Posted at

概要

vistaでandroid studio 1.1.0やってみた。
jniやってみた。
練習問題やってみた。

練習問題

jniでログを吐け。

サンプルコード

#include <jni.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <android/log.h>

JNIEXPORT jstring JNICALL Java_com_ohisamallc_ohiapp154_ohiapp154_MainActivity_hello(JNIEnv * env, jobject thiz) {
    char buf[456];
    const char * s0 = "ズン ";
    const char * s1 = "ドコ ";
    const char * s2 = "ドコ キヨシ!!";
    int i = 0;
    int n = 0;
    while (i == 0)
    {
        if ((rand() & 1) > 0)
        {
            strcat(buf, s1);
            n = 0;
        }
        else
        {
            strcat(buf, s0);
            n++;
        }
        if (n == 4)
        {
            strcat(buf, s2);
            break;
        }
        __android_log_print(ANDROID_LOG_ERROR, "ohi", "Hello %d", n);
    }
	return (* env)->NewStringUTF(env, buf);
}


Android.mk

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

実行結果

09-14 05:04:52.408    6324-6356/com.ohisamallc.ohiapp154.ohiapp154 D/OpenGLRenderer? Render dirty regions requested: false
09-14 05:04:52.486    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 D/Atlas? Validating map...
09-14 05:04:52.767    6324-6356/com.ohisamallc.ohiapp154.ohiapp154 D/libEGL? loaded /system/lib/egl/libEGL_tegra.so
09-14 05:04:52.782    6324-6356/com.ohisamallc.ohiapp154.ohiapp154 D/libEGL? loaded /system/lib/egl/libGLESv1_CM_tegra.so
09-14 05:04:52.818    6324-6356/com.ohisamallc.ohiapp154.ohiapp154 D/libEGL? loaded /system/lib/egl/libGLESv2_tegra.so
09-14 05:04:52.851    6324-6356/com.ohisamallc.ohiapp154.ohiapp154 I/OpenGLRenderer? Initialized EGL, version 1.4
09-14 05:04:52.860    6324-6356/com.ohisamallc.ohiapp154.ohiapp154 D/OpenGLRenderer? Enabling debug mode 0
09-14 05:04:55.102    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 1
09-14 05:04:55.103    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 2
09-14 05:04:55.103    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 0
09-14 05:04:55.103    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 1
09-14 05:04:55.103    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 2
09-14 05:04:55.103    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 0
09-14 05:04:55.103    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 1
09-14 05:04:55.103    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 2
09-14 05:04:55.103    6324-6324/com.ohisamallc.ohiapp154.ohiapp154 E/ohi? Hello 3

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0