编译因OpenSSL项目中缺少标头而导致的错误

时间:2018-01-29 07:27:47

标签: android gradle android-ndk openssl java-native-interface

我在项目中使用PreSilt OpenSSL库,但我收到错误:

Error:(62, 11) fatal error: 'openssl/asn1.h' file not found
Error:(62, 11) fatal error: 'openssl/asn1.h' file not found

我的Android.mk文件在这里

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := myLibrary
TARGET_PLATFORM := android-3
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/src/main/jni/include/openssl
LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)

在rss.h中收到错误

rsa.h的标题

# include <openssl/asn1.h>    
# ifndef OPENSSL_NO_BIO
#  include <openssl/bio.h>
# endif
# include <openssl/crypto.h>
# include <openssl/ossl_typ.h>
# ifndef OPENSSL_NO_DEPRECATED
#  include <openssl/bn.h>
# endif

这里的错误是找不到OpenSSL

build.graddle

apply plugin: 'com.android.application'

android {
    signingConfigs {
        config {
            keyAlias 'manvish'

        }
    }

        compileSdkVersion 25
        buildToolsVersion '26.0.2'
        defaultConfig {
            applicationId "com.example.manvish.bwssb"
            minSdkVersion 19
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            vectorDrawables.useSupportLibrary = true
            multiDexEnabled true
            ndk {
                moduleName "myLibrary"
            }
        }

        buildTypes {
            release {

                shrinkResources false
                minifyEnabled true
                zipAlignEnabled true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                        'proguard-rules.pro'
                signingConfig signingConfigs.config

                debuggable true
            }
            debug {
                shrinkResources false
                minifyEnabled true
                zipAlignEnabled true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                        'proguard-rules.pro'
                signingConfig signingConfigs.config

                debuggable true
            }
        }
        }



    android {
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }

    }

    android {
        defaultConfig {

                ndk {
                    moduleName "myLibrary"
                    ldLibs "log"
                }

        }
        externalNativeBuild {
            ndkBuild {
                path 'src/main/jni/Android.mk'
            }
        }
    }

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-vector-drawable:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'xyz.danoz:recyclerviewfastscroller:0.1.3'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'
    compile files('libs/MorphoSmart_SDK_6.13.2.0-4.1.jar')

    //    compile 'com.google.android.gms:play-services-location:11.0.4'

    //    compile 'com.google.android.gms:play-services-maps:11.0.4'
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/core.jar')
    compile('org.apache.httpcomponents:httpmime:4.3') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
    compile('org.apache.httpcomponents:httpcore:4.4.1') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'

    }
    compile 'com.google.code.gson:gson:2.7'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile files('libs/zip4j_1.3.2.jar')
    compile files('libs/idkit.jar')
    compile files('libs/jna-4.0.0.jar')
    compile 'org.apache.commons:commons-lang3:3.6'
    compile 'com.github.bumptech.glide:glide:3.7.0'
}

我在适当的文件夹中添加了.so文件。 已经四天了,我无法解决这个问题。

请帮帮我们。

1 个答案:

答案 0 :(得分:2)

您的 Android.mk 位于${proj}/src/main/jni,即$(LOCAL_PATH)。因此,您应该使用

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include

这会将${proj}/src/main/jni/include/openssl/asn1.h视为

#include <openssl/asn1.h>