生成C ++头文件android

时间:2016-04-20 23:14:29

标签: java android c++

我一直在尝试创建一个C++ header文件3天,我在Github上下载了一个使用C++的项目,问题是我想要修改项目,因为它只能运行在{ {1}}架构。我想为armeabi-v7a.so生成armeabi-v7a个文件,下面是java类:

x86

Android.mk文件:

package me.myname.scanner.scanlibrary
/**
* Created by jhansi on 28/03/15.
 */

public class ScanActivity extends Activity implements IScanner {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scan_layout);
    init();
}

private void init() {
    PickImageFragment fragment = new PickImageFragment();
    Bundle bundle = new Bundle();
    bundle.putInt(ScanConstants.OPEN_INTENT_PREFERENCE, getPreferenceContent());
    fragment.setArguments(bundle);
    android.app.FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.content, fragment);
    fragmentTransaction.commit();
}

protected int getPreferenceContent() {
    return getIntent().getIntExtra(ScanConstants.OPEN_INTENT_PREFERENCE, 0);
}

@Override
public void onBitmapSelect(Uri uri) {
    ScanFragment fragment = new ScanFragment();
    Bundle bundle = new Bundle();
    bundle.putParcelable(ScanConstants.SELECTED_BITMAP, uri);
    fragment.setArguments(bundle);
    android.app.FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.content, fragment);
    fragmentTransaction.addToBackStack(ScanFragment.class.toString());
    fragmentTransaction.commit();
}

@Override
public void onScanFinish(Uri uri) {
    ResultFragment fragment = new ResultFragment();
    Bundle bundle = new Bundle();
    bundle.putParcelable(ScanConstants.SCANNED_RESULT, uri);
    fragment.setArguments(bundle);
    android.app.FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.content, fragment);
    fragmentTransaction.addToBackStack(ResultFragment.class.toString());
    fragmentTransaction.commit();
}

public native Bitmap getScannedBitmap(Bitmap bitmap, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);

public native Bitmap getGrayBitmap(Bitmap bitmap);

public native Bitmap getMagicColorBitmap(Bitmap bitmap);

public native Bitmap getBWBitmap(Bitmap bitmap);

public native float[] getPoints(Bitmap bitmap);

static {
    System.loadLibrary("opencv_java");
    System.loadLibrary("Scanner");
}

Application.mk

LOCAL_PATH := $(call my-dir)
//point of mofication
APP_ABI := x86 armeabi
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
include sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := Scanner
LOCAL_SRC_FILES := scan.cpp
LOCAL_LDLIBS    += -lm -llog -landroid
LOCAL_LDFLAGS += -ljnigraphics
include $(BUILD_SHARED_LIBRARY)

顶级gradle.build

APP_STL := stlport_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI :=  x86 armeabi
APP_PLATFORM := android-14

}

gradle.properties

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
    applicationId "me.myname.scanner"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled false
    ndk
            {
                moduleName "Scanner"
            }
}


sourceSets.main
        {
            jni.srcDirs = []
            jniLibs.srcDir 'src/main/libs'
        }


buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
}

但即使在这之后我无法生成# Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m - XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/ multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true android.useDeprecatedNdk=true 文件和Header,我的项目结构如图所示

Project Structure

这是我第一次与.so打交道,我已经阅读并观看过一堆视频,但这对我不起作用。所有帮助将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

我终于找到了为什么我的代码没有生成任何header.so文件的原因,首先有时似乎ndk可能有点偏离,就像我的一样,它只是不工作,没有错误。我设法手动生成头文件,我通过java cmd导航到我的admin目录,以避免任何可能需要管理权限的错误然后输入命令javah -d jni -classpath c/path/to/android/sdk/compileplatform/android.jar; c/path/to/app/build/intermediates/classes/debug -force com.package.containing.my.class.andtheclassitself 这会生成头文件,然后我继续导航到ndk根目录并输入命令ndk-build NDK_PROJECT_PATH=c/path/to/my/app/src/main APP_BUID_SCRIPT=c/path/to/my/project/Android.mk这编译了我的.so文件。