问题描述
我想交叉编译我的Android项目。我创建了〜/ .cargo / config,如下所示:-
login(uname: string,pwd: string) {
try {
const userAndPasswordBase24 = btoa(uname + ':' + pwd);
localStorage.setItem('authKey',userAndPasswordBase24);
//create authorized header
const headers = new HttpHeaders({ "Authorization" : 'Basic ' + userAndPasswordBase24,"Content-Type": "application/json"});
this.showLoader = true;
this.showError = false;
this.loginFailed = false;
this.checkLoginUser(headers).subscribe(
(user) => {
if (user) {
this.isLogin = true;
this.showLoader = false;
this.showError = false;
}
},(error) => {
this.showLoader = false;
this.showError = true;
}
);
} catch (error) {
this.showLoader = false;
this.loginFailed = true;
}
}
这是我的项目的Cargo.toml文件:-
[target.armv7-linux-androideabi]
ar = "/optHDD/AndroidNDK/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
linker = "/optHDD/AndroidNDK/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi26-clang"
它可以在Desktop linux上编译并正常工作
但是它不能为Android Linux编译。我用rustup添加了目标armv7-linux-androideabi
[package]
name = "examer"
version = "0.1.0"
authors = ["none"]
edition = "2018"
[dependencies]
tokio = { version = "0.2",features = ["full"] }
lazy_static = "1"
clap = "2.*"
futures = { version = "0.3",default-features = false,features = ["alloc"] }
futures-util = "0.3"
async-tungstenite = { version = "*",features= ["tokio-runtime"] }
mongodb = { version = "1.*",features = ["tokio-runtime"] }
pbkdf2 = "0.2"
# serde = { version = "1.0",features = ["derive","rc"] }
serde_cbor = "0.11"
derive_builder = "0.9.0"
# serde_derive = "1.0"
[dev-dependencies]
tungstenite = "0.11"
url = "2"
[lib]
name = "libexamer"
path = "src/lib.rs"
[[bin]]
name = "examer"
path = "src/main.rs"
所以我接下来尝试添加PKG_CONfig_ALLOW_CROSS = 1,但同样失败
❯ cargo build --target armv7-linux-androideabi
... Compling Very long list of packages So i trimmed it...
error: Failed to run custom build command for `openssl-sys v0.9.58`
Caused by:
process didn't exit successfully: `/home/noone/examer/target/debug/build/openssl-sys-d34551fe3fadea5f/build-script-main` (exit code: 101)
--- stdout
cargo:rustc-cfg=const_fn
cargo:rerun-if-env-changed=ARMV7_LINUX_ANDROIDEABI_OPENSSL_LIB_DIR
ARMV7_LINUX_ANDROIDEABI_OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=ARMV7_LINUX_ANDROIDEABI_OPENSSL_INCLUDE_DIR
ARMV7_LINUX_ANDROIDEABI_OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=ARMV7_LINUX_ANDROIDEABI_OPENSSL_DIR
ARMV7_LINUX_ANDROIDEABI_OPENSSL_DIR unset
cargo:rerun-if-env-changed=OPENSSL_DIR
OPENSSL_DIR unset
cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONfig
cargo:rerun-if-env-changed=PKG_CONfig_ALLOW_CROSS_armv7-linux-androideabi
cargo:rerun-if-env-changed=PKG_CONfig_ALLOW_CROSS_armv7_linux_androideabi
cargo:rerun-if-env-changed=TARGET_PKG_CONfig_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONfig_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONfig_armv7-linux-androideabi
cargo:rerun-if-env-changed=PKG_CONfig_armv7_linux_androideabi
cargo:rerun-if-env-changed=TARGET_PKG_CONfig
cargo:rerun-if-env-changed=PKG_CONfig
cargo:rerun-if-env-changed=PKG_CONfig_SYSROOT_DIR_armv7-linux-androideabi
cargo:rerun-if-env-changed=PKG_CONfig_SYSROOT_DIR_armv7_linux_androideabi
cargo:rerun-if-env-changed=TARGET_PKG_CONfig_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONfig_SYSROOT_DIR
run pkg_config fail: "Cross compilation detected. Use PKG_CONfig_ALLOW_CROSS=1 to override"
--- stderr
thread 'main' panicked at '
Could not find directory of OpenSSL installation,and this `-sys` crate cannot
proceed without this kNowledge. If OpenSSL is installed and this crate had
trouble finding it,you can set the `OPENSSL_DIR` environment variable for the
compilation process.
Make sure you also have the development packages of openssl installed.
For example,`libssl-dev` on Ubuntu or `openssl-devel` on Fedora.
If you're in a situation where you think the directory *should* be found
automatically,please open a bug at https://github.com/sfackler/rust-openssl
and include information about your system as well as this message.
$HOST = x86_64-unkNown-linux-gnu
$TARGET = armv7-linux-androideabi
openssl-sys = 0.9.58
',/home/noone/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.58/build/find_normal.rs:157:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build Failed,waiting for other jobs to finish...
error: build Failed
经过一番谷歌搜索,我发现人们建议手动设置AR和CC环境变量,所以我也这样做了
❯ PKG_CONfig_ALLOW_CROSS=1 cargo build --target armv7-linux-androideabi
Compiling ring v0.16.15
Compiling openssl-sys v0.9.58
Compiling proc-macro2 v0.4.30
Compiling httparse v1.3.4
Compiling quote v1.0.7
Compiling getrandom v0.1.14
Compiling generic-array v0.12.3
Compiling net2 v0.2.34
error: Failed to run custom build command for `ring v0.16.15`
Caused by:
process didn't exit successfully: `/home/noone/examer/target/debug/build/ring-039ac27f87884aa1/build-script-build` (exit code: 101)
--- stdout
OPT_LEVEL = Some("0")
TARGET = Some("armv7-linux-androideabi")
HOST = Some("x86_64-unkNown-linux-gnu")
CC_armv7-linux-androideabi = None
CC_armv7_linux_androideabi = None
TARGET_CC = None
CC = None
CFLAGS_armv7-linux-androideabi = None
CFLAGS_armv7_linux_androideabi = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
--- stderr
ENV ANDROID_HOME=/optHDD/AndroidSDK
ENV ANDROID_NDK=/optHDD/AndroidNDK
ENV ANDROID_NDK_ROOT=/optHDD/AndroidNDK
ENV ANDROID_SDK_ROOT=/optHDD/AndroidSDK
ENV BINARYEN=/usr
ENV BINARYEN_ROOT=/usr
ENV CARGO=/home/noone/.rustup/toolchains/stable-x86_64-unkNown-linux-gnu/bin/cargo
ENV CARGO_CFG_TARGET_ARCH=arm
ENV CARGO_CFG_TARGET_ENDIAN=little
ENV CARGO_CFG_TARGET_ENV=
ENV CARGO_CFG_TARGET_FAMILY=unix
ENV CARGO_CFG_TARGET_OS=android
ENV CARGO_CFG_TARGET_POINTER_WIDTH=32
ENV CARGO_CFG_TARGET_vendOR=unkNown
ENV CARGO_CFG_UNIX=
ENV CARGO_FEATURE_ALLOC=1
ENV CARGO_FEATURE_DEFAULT=1
ENV CARGO_FEATURE_DEV_URANDOM_FALLBACK=1
ENV CARGO_FEATURE_ONCE_CELL=1
ENV CARGO_HOME=/home/noone/.cargo
ENV CARGO_MAKEFLAGS=--jobserver-fds=5,6 -j --jobserver-auth=5,6 -j
ENV CARGO_MANIFEST_DIR=/home/noone/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.15
ENV CARGO_MANIFEST_LINKS=ring-asm
ENV CARGO_PKG_AUTHORS=Brian nooneh <brian@briannooneh.org>
ENV CARGO_PKG_DESCRIPTION=Safe,fast,small crypto using Rust.
ENV CARGO_PKG_HOMEPAGE=
ENV CARGO_PKG_NAME=ring
ENV CARGO_PKG_REPOSITORY=https://github.com/briannooneh/ring
ENV CARGO_PKG_VERSION=0.16.15
ENV CARGO_PKG_VERSION_MAJOR=0
ENV CARGO_PKG_VERSION_MInor=16
ENV CARGO_PKG_VERSION_PATCH=15
ENV CARGO_PKG_VERSION_PRE=
ENV LD_LIBRARY_PATH=/home/noone/examer/target/debug/deps:/home/noone/examer/target/debug:/home/noone/.rustup/toolchains/stable-x86_64-unkNown-linux-gnu/lib/rustlib/x86_64-unkNown-linux-gnu/lib:/home/noone/.rustup/toolchains/stable-x86_64-unkNown-linux-gnu/lib
ENV NUM_JOBS=8
ENV OPT_LEVEL=0
ENV OUT_DIR=/home/noone/examer/target/armv7-linux-androideabi/debug/build/ring-bb7f58c397198b7c/out
ENV PATH=/home/noone/.cargo/bin:/opt/google-cloud-sdk/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/lib/emscripten:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/noone/.gem/ruby/2.7.0/bin:/opt/scripts:/usr/lib/servo:/home/noone/.rvm/bin
ENV PKG_CONfig_ALLOW_CROSS=1
ENV PROFILE=debug
ENV RUSTC=rustc
ENV RUSTC_LINKER=/optHDD/AndroidNDK/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi26-clang
ENV RUSTDOC=rustdoc
ENV RUSTUP_HOME=/home/noone/.rustup
ENV RUSTUP_TOOLCHAIN=stable-x86_64-unkNown-linux-gnu
ENV RUST_RECURSION_COUNT=1
ENV SHELL=/bin/sh
ENV SHELL_SESSION_ID=2f2df9d05d444290bf71a1767feb62d7
ENV SHLVL=1
ENV SSL_CERT_DIR=/etc/ssl/certs
ENV SSL_CERT_FILE=/etc/ssl/cert.pem
ENV TARGET=armv7-linux-androideabi
ENV _=/usr/bin/cargo
running "arm-linux-androideabi-clang" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=armv7-linux-androideab-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat"-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wunialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/home/noone/examer/target/armv7-linux-androideabi/debuild/ring-bb7f58c397198b7c/out/aesv8-armx-linux32.o" "/home/noone/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.15/pregenerated/aesv8-armx-linux32.S"
thread 'main' panicked at 'Failed to execute ["arm-linux-androideabi-clang" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-poi" "--target=armv7-linux-androideabi" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wecompare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compareWsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/home/noone/ex/target/armv7-linux-androideabi/debug/build/ring-bb7f58c397198b7c/out/aesv8-armx-linux32.o" "/home/noone/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.15/prerated/aesv8-armx-linux32.S"]: No such file or directory (os error 2)',/home/noone/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.15/build.rs:661:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build Failed,waiting for other jobs to finish...
error: build Failed
解决方法
我已经通过在Cargo.toml中添加以下内容暂时解决了该问题
package com....getterclasses.checkconfig;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import com.groupama.intra.devops.getterclasses.Content;
@Entity
public class CheckConfigDeploiementLecture extends Content {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String namespacename;
private String servicename;
private String typeverification;
private String status;
private String details;
private String reportdate;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNamespacename() {
return namespacename;
}
public void setNamespacename(String namespacename) {
this.namespacename = namespacename;
}
public String getServicename() {
return servicename;
}
public void setServicename(String servicename) {
this.servicename = servicename;
}
public String getTypeverification() {
return typeverification;
}
public void setTypeverification(String typeverification) {
this.typeverification = typeverification;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getReportdate() {
return reportdate;
}
public void setReportdate(String reportdate) {
this.reportdate = reportdate;
}
}
[target.armv7-linux-androideabi.dependencies]
openssl = { version = "*",features = ["vendored"] }
为我静态构建openssl。