Tag Archives: native

[Solved] AndroidStudio libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined referen

1. Error reporting:

The error of Android C + + OpenSSL link is as follows:

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigfillset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'tcgetattr'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'

clang++: error: linker command failed with exit code 1 (use -v to see invocation)

2. Reason:

Sigdelset, sigfillset and signal cannot be found in the SDK of Android

3. Solution:

Modify the minSdkVersion of build.grandle to a version number after 21:

apply plugin: 'com.android.application'
def LIBWEBRTC_HOME_PATH = "I:/webrtc/android/webrtc_m84_20201001/webrtc_android/src/"
//def LIBWEBRTC_HOME_PATH = "I:/webrtc/android/androidnativeapi/app/webrtc/"
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "org.webrtc.examples.androidnativeapi"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                arguments "-DLIBWEBRTC_HOME_PATH=" + LIBWEBRTC_HOME_PATH,
                        "-DANDROID_STL=c++_static"
            }
        }
        ndk {
            abiFilters  "armeabi-v7a"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    sourceSets {
        main {
            // 1. configure the root directory libs to load third-party so libraries, (it is best not to create jniLibs, in the many open source libraries may cause conflicts, not yet found)
            // 2. automatically copy the so libraries in the libs directory to the specified directory when running
            // 3. If you don't need to recompile the so you created, you can copy the so generated by (app/build/intermediates/transforms) to this directory
            jniLibs.srcDirs = ['libs']
            // If it is a single folder, you can directly configure it as follows
            // jniLibs.srcDir 'libs'
        }
    }
    buildToolsVersion '28.0.2'//ADD
}
repositories {
    flatDir{
        dirs'libs'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.aar"])

    //implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    //implementation(name: 'libwebrtc', ext: 'aar')
    //implementation 'org.webrtc:google-webrtc:1.0.+'
}

not found libc++.so

Problem: the installation of install depends on the APK with so library, so it can’t load so normally. Error: not found libc + +. So
for example: system. Loadlibrary (“inittest”);

analysis:

    on Android/prebuilds/tools/GCC SDK, run the following command:
    readelf – DW libinittest. So
    to view the dynamic dependency Library of libinittest. So. Since relying on libc + +. So Android n, Google has contracted the dependent permissions of so library. Only the application under system/APP system/priv app can be relied on. Some so libraries cannot be loaded by the installation application under data/APP
    the following/system/etc/public.libraries.txt is the white list of dynamically dependent libraries. Libc + +. So is not among them

    libandroid.so
    libaaudio.so
    libamidi.so
    libbinder_ndk.so
    libc.so
    libcamera2ndk.so
    libdl.so
    libEGL.so
    libGLESv1_CM.so
    libGLESv2.so
    libGLESv3.so
    libicui18n.so
    libicuuc.so
    libjnigraphics.so
    liblog.so
    libmediandk.so
    libm.so
    libnativewindow.so
    libneuralnetworks.so
    libOpenMAXAL.so
    libOpenSLES.so
    libRS.so
    libstdc++.so
    libsync.so
    libvulkan.so
    libwebviewchromium_plat_support.so
    libz.so
    

    Scheme 1:
    add libc + +. So to the white list

    Scheme 2:
    add the following configuration in the source code android.mk of libinittest.so:

    LOCAL_NDK_STL_VARIANT := c++_static
    LOCAL_SDK_VERSION := 8
    

    Scheme 3:
    copy libc + +. So to the same level directory of libinittest.so in your app to generate APK.

React Native Network Request Failed solution

Today, when I was writing a demo of Network Request with React Native, the emulators kept telling me Network Request Failed, which was very annoying, baidu search for a long time did not find the answer I wanted, someone said on stackoverflow that this error only appeared in the development mode, but the production version would not appear, but it didn’t solve the problem at all. Another says: If you’re using FETCH to get data, and you’re using POST, notice that Headers has to add a request header. You can’t use the body when the request is for GET, you must include the body when it is for POST, and once you set the header, everything works fine. However, the fetch method used by me does not need to add any headers, so the problem of Network Request Failed has not been solved.
To prevent code errors, I directly copied the official sample code, as follows

fetch('http://facebook.github.io/react-native/movies.json')
      .then((response) => response.json())
      .then((responseJson) => {
        console.log(responseJson.movies);
        return responseJson.movies;
      })
      .catch((error) => {
        console.error(error);
      });

I put this code directly into the browser console console to run, and found that everything was ok, the console successfully output content. Then it could be the ios emulator.
Now that fecth API is problematic try using XMLHttpRequest instead, and the console output the Resource could not be loaded because the app Transport Security policy requires the use of a secure Connection, Baidu search only found that iOS9 introduced the new feature App Transport Security (ATS). The new feature requires that networks accessed within the App must use the HTTPS protocol, meaning that the Api interface must be HTTPS in the future. But my project USES HTTP, and I can’t immediately switch to HTTPS for transport.
Fortunately there is an alternative solution
1. Add NSAppTransportSecurity type Dictionary to info.plist.
2. Add nsallowsarbitraryoccurrence type Boolean under NSAppTransportSecurity, value set to YES
For details, please refer to this document for the resolution that iOS9 HTTP does not work properly