shadowsocks / shadowsocks-android

A shadowsocks client for Android
Other
35.23k stars 11.57k forks source link

Docker build failed #2848

Closed VictorSnow closed 1 year ago

VictorSnow commented 2 years ago

Describe the bug Failed to build from source using docker

To Reproduce Steps to reproduce the behavior:

  1. cd core/src/main/rust/shadowsocks-rust
  2. rustup target add armv7-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android
  3. Run in root directory docker run --rm -v ${PWD}:/build -w /build shadowsocks/android-ndk-go ./gradlew assembleDebug
  4. Errors like
    
    Downloading crates ...
    Downloaded env_logger v0.9.0 (registry `https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git`)
    Compiling libc v0.2.98
    Compiling proc-macro2 v1.0.28
    Compiling unicode-xid v0.2.2
    Compiling syn v1.0.74
    Compiling autocfg v1.0.1
    Compiling cfg-if v1.0.0
    error[E0463]: can't find crate for `core`
    |
    = note: the `armv7-linux-androideabi` target may not be installed
    = help: consider downloading the target with `rustup target add armv7-linux-androideabi`
    = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: aborting due to previous error

For more information about this error, try rustc --explain E0463. error: could not compile cfg-if


**Expected behavior**
Build Success

**Screenshots**

**Smartphone (please complete the following information):**

**Configuration**

**Additional context**
I am building on macos using docker

Macx@A1398 shadowsocks-rust % rustup show Default host: x86_64-apple-darwin rustup home: /Users/xxxx/.rustup

installed toolchains

stable-x86_64-apple-darwin (default) nightly-2021-06-03-x86_64-apple-darwin

installed targets for active toolchain

aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-apple-darwin x86_64-linux-android

active toolchain

nightly-2021-06-03-x86_64-apple-darwin (overridden by '/Users/xxxxx/Desktop/shadowsocks-android/core/src/main/rust/shadowsocks-rust/rust-toolchain') rustc 1.54.0-nightly (dbe459ded 2021-06-02)

VictorSnow commented 2 years ago

A workround: skip step 1 and 2

Add Script docker-exec.sh in root project dir

#!/bin/sh

cd core/src/main/rust/shadowsocks-rust
rustup target add armv7-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android

cd /build/
./gradlew assembleDebug

Then

docker run --rm -v ${PWD}:/build -w /build shadowsocks/android-ndk-go /build/docker-exec.sh

Builded success on mobile Apk

Addition If failed in resolve rust dependence, you may want to add to core/src/main/rust/shadowsocks-rust/.cargo/config.toml

[source.crates-io]
replace-with = 'tuna'

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
VictorSnow commented 2 years ago

Trouble in build TV version

> Task :tv:getDependencies
Failed to process com.github.shadowsocks:plugin:2.0.1
org.gradle.internal.component.AmbiguousVariantSelectionException: The consumer was configured to find an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'market' with value 'freedom', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :plugin:
  - Configuration ':plugin:debugApiElements' variant android-aidl declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
      - Unmatched attributes:
          - Provides attribute 'artifactType' with value 'android-aidl' but the consumer didn't ask for it
          - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
          - Doesn't say anything about market (required 'freedom')
          - Doesn't say anything about its target Java environment (preferred optimized for Android)
  - Configuration ':plugin:debugApiElements' variant android-lint-local-aar declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':

Error.log