Hello-jni 示例在 Android Studio 2.0 预览版中不起作用 [英] Hello-jni sample doesn't work in Android Studio 2.0 Preview

查看:28
本文介绍了Hello-jni 示例在 Android Studio 2.0 预览版中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施

在我的代码的某些部分中,我导入了这个:

静态{System.loadLibrary("hello-jni");}public static native int testMethod();

并通过自动完成创建hello-jni.c:

#include "hello-jni.h"JNIEXPORT jintJNICALLJava_lala_lala_HomeScreen_testMethod(JNIEnv*环境,jclass 类型){//去做}

头文件hello-jni.h:

<代码>////由 Filip 在 15.12.2015 创建..//#ifndef PHOTO_HELLO_JNI_H#define PHOTO_HELLO_JNI_H#endif//PHOTO_HELLO_JNI_H

但它不起作用.它是全红色的:

什么问题?如何解决?

解决方案

Android studio 的问题,但仅在 Windows 上:问题 195483
你可以降级到 Android studio 1.5.1, gradle 2.8, 实验性包装器 0.4.0.
我尝试了 Android Studio 2.0 beta 6,带有包装器 0.6.0-beta5 和 0.6.0-beta6,但仍然不起作用.

I'm trying to implement hello-jni sample into my project. I have Gradle 2.8 and 'com.android.tools.build:gradle-experimental:0.4.0' and using Android Studio 2.0 Preview 3b.

This is my build.gradle:

apply plugin: 'com.android.model.application'
model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"
        defaultConfig.with {
            applicationId = "lala.lala"
            minSdkVersion.apiLevel = 16
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = "1.0"
        }
    }
    /*
    * native build settings
    */
    android.ndk {
        moduleName = "hello-jni"


        //  cppFlags.add("-fno-rtti")
     //    cppFlags.add("-fno-exceptions")
     //   ldLibs.addAll(["android", "log"])
      //  stl       = "system"

    }

    android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("arm") {
            ndk.abiFilters.add("armeabi")
        }
        create("arm7") {
            ndk.abiFilters.add("armeabi-v7a")
        }
        create("arm8") {
            ndk.abiFilters.add("arm64-v8a")
        }
        create("x86") {
            ndk.abiFilters.add("x86")
        }
        create("x86-64") {
            ndk.abiFilters.add("x86_64")
        }
        create("mips") {
            ndk.abiFilters.add("mips")
        }
        create("mips-64") {
            ndk.abiFilters.add("mips64")
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            //proguardFiles.add(file('proguard-rules.txt'))
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile 'com.google.android.gms:play-services-analytics:8.3.0'
    compile 'com.google.android.gms:play-services-appindexing:8.3.0'
}

I have created in JNI folder hello-jni.h:

In some part of my code I import this:

static {
    System.loadLibrary("hello-jni");
}
public static native int testMethod();

And by auto completion created hello-jni.c:

#include "hello-jni.h"

JNIEXPORT jintJNICALL
Java_lala_lala_HomeScreen_testMethod(JNIEnv
*env,
jclass type
)
{
// TODO
}

Header file hello-jni.h:

//
// Created by Filip on 15.12.2015..
//

#ifndef PHOTO_HELLO_JNI_H
#define PHOTO_HELLO_JNI_H

#endif //PHOTO_HELLO_JNI_H

But it doesn't work. It is full red:

What is problem? How to solve it?

解决方案

It's problem in Android studio, but just on Windows: Issue 195483
You can downgrade to Android studio 1.5.1, gradle 2.8, experimental wrapper 0.4.0.
I tried Android Studio 2.0 beta 6, with wrapper 0.6.0-beta5 and 0.6.0-beta6, but still doesn't work.

这篇关于Hello-jni 示例在 Android Studio 2.0 预览版中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆