cake-tech / cake_wallet

The open source repository for Cake Wallet, a noncustodial multi-currency wallet, and Monero.com, a noncustodial Monero-only wallet. Need help? Check out https://guides.cakewallet.com
https://cakewallet.com
MIT License
618 stars 171 forks source link

Building CakeWallet Android App 4.4.0 failed with haven_wallet errors, Missing cw_haven realted build instructions? #337

Open emanuelb opened 2 years ago

emanuelb commented 2 years ago

Build 4.4.0 failed with errors:

cw_haven/lib/haven_wallet.dart:32:6: Error: Error when reading 'cw_haven/lib/haven_wallet.g.dart': No such file or directory

part 'haven_wallet.g.dart';

     ^

cw_haven/lib/haven_transaction_history.dart:6:6: Error: Error when reading 'cw_haven/lib/haven_transaction_history.g.dart': No such file or directory

part 'haven_transaction_history.g.dart';

     ^

cw_haven/lib/haven_wallet_addresses.dart:9:6: Error: Error when reading 'cw_haven/lib/haven_wallet_addresses.g.dart': No such file or directory

part 'haven_wallet_addresses.g.dart';

     ^

cw_haven/lib/haven_account_list.dart:6:6: Error: Error when reading 'cw_haven/lib/haven_account_list.g.dart': No such file or directory

part 'haven_account_list.g.dart';

     ^

cw_haven/lib/haven_subaddress_list.dart:7:6: Error: Error when reading 'cw_haven/lib/haven_subaddress_list.g.dart': No such file or directory

part 'haven_subaddress_list.g.dart';

     ^

cw_haven/lib/haven_wallet.dart:32:6: Error: Can't use 'cw_haven/lib/haven_wallet.g.dart' as a part, because it has no 'part of' declaration.

part 'haven_wallet.g.dart';

     ^

cw_haven/lib/haven_transaction_history.dart:6:6: Error: Can't use 'cw_haven/lib/haven_transaction_history.g.dart' as a part, because it has no 'part of' declaration.

part 'haven_transaction_history.g.dart';

     ^

cw_haven/lib/haven_wallet_addresses.dart:9:6: Error: Can't use 'cw_haven/lib/haven_wallet_addresses.g.dart' as a part, because it has no 'part of' declaration.

part 'haven_wallet_addresses.g.dart';

     ^

cw_haven/lib/haven_account_list.dart:6:6: Error: Can't use 'cw_haven/lib/haven_account_list.g.dart' as a part, because it has no 'part of' declaration.

part 'haven_account_list.g.dart';

     ^

cw_haven/lib/haven_subaddress_list.dart:7:6: Error: Can't use 'cw_haven/lib/haven_subaddress_list.g.dart' as a part, because it has no 'part of' declaration.

part 'haven_subaddress_list.g.dart';

     ^

cw_haven/lib/haven_wallet.dart:36:42: Error: Type '_$HavenWallet' not found.

class HavenWallet = HavenWalletBase with _$HavenWallet;

                                         ^^^^^^^^^^^^^

cw_haven/lib/haven_transaction_history.dart:9:10: Error: Type '_$HavenTransactionHistory' not found.

    with _$HavenTransactionHistory;

         ^^^^^^^^^^^^^^^^^^^^^^^^^

cw_haven/lib/haven_wallet_addresses.dart:12:10: Error: Type '_$HavenWalletAddresses' not found.

    with _$HavenWalletAddresses;

         ^^^^^^^^^^^^^^^^^^^^^^

cw_haven/lib/haven_account_list.dart:8:52: Error: Type '_$HavenAccountList' not found.

class HavenAccountList = HavenAccountListBase with _$HavenAccountList;

                                                   ^^^^^^^^^^^^^^^^^^

cw_haven/lib/haven_subaddress_list.dart:10:10: Error: Type '_$HavenSubaddressList' not found.

    with _$HavenSubaddressList;

         ^^^^^^^^^^^^^^^^^^^^^

cw_haven/lib/haven_wallet.dart:36:7: Error: The type '_$HavenWallet' can't be mixed in.

class HavenWallet = HavenWalletBase with _$HavenWallet;

      ^

cw_haven/lib/haven_transaction_history.dart:8:7: Error: The type '_$HavenTransactionHistory' can't be mixed in.

class HavenTransactionHistory = HavenTransactionHistoryBase

      ^

cw_haven/lib/haven_subaddress_list.dart:9:7: Error: The type '_$HavenSubaddressList' can't be mixed in.

class HavenSubaddressList = HavenSubaddressListBase

      ^

cw_haven/lib/haven_wallet_addresses.dart:11:7: Error: The type '_$HavenWalletAddresses' can't be mixed in.

class HavenWalletAddresses = HavenWalletAddressesBase

      ^

cw_haven/lib/haven_account_list.dart:8:7: Error: The type '_$HavenAccountList' can't be mixed in.

class HavenAccountList = HavenAccountListBase with _$HavenAccountList;

      ^

FAILURE: Build failed with an exception.

* Where:

Script '/home/appuser/app/sdk/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 991

* What went wrong:

Execution failed for task ':app:compileFlutterBuildRelease'.

> Process 'command '/home/appuser/app/sdk/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Running: cd cw_haven && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. ;

as it's looks like errors cause such command is missing in build instructions, maybe loop over array instead that contain the cw_strings values instead, as it run the same commands just in different directory.

Return:

Running "flutter pub get" in cw_haven...                         2,868ms
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The plugin `cw_haven` requires your app to be migrated to the Android embedding v2. Follow the steps on https://flutter.dev/go/android-project-migration and re-run this command.

Above warning which cause error in this case happened in previous compiling steps, issue opened for it is: #335

Containerfile to reproduce:

FROM docker.io/ubuntu:rolling

RUN set -ex; \
    apt-get update; \
    DEBIAN_FRONTEND=noninteractive apt-get install --yes -o APT::Install-Suggests=false --no-install-recommends \
        openjdk-11-jdk curl unzip automake build-essential file pkg-config git python libtool libtinfo5 cmake clang; \
    rm -rf /var/lib/apt/lists/*; \
    useradd -ms /bin/bash appuser; \
    mkdir -p /opt/android/; \
    chown appuser:root /opt/android/;

USER appuser

ENV ANDROID_SDK_ROOT="/home/appuser/app/sdk" \
    ANDROID_HOME="/home/appuser/app/sdk"

RUN set -ex; \
    mkdir -p "/home/appuser/app/sdk/licenses"; \
    printf "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "/home/appuser/app/sdk/licenses/android-sdk-license"; \
    cd /home/appuser/app/sdk; \
    curl -o "flutter_linux_2.0.4-stable.tar.xz" https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_2.0.4-stable.tar.xz; \
    tar xf flutter_linux_2.0.4-stable.tar.xz; \
    rm flutter_linux_2.0.4-stable.tar.xz; \
    /home/appuser/app/sdk/flutter/bin/flutter config --no-analytics; \
    /home/appuser/app/sdk/flutter/bin/dart --disable-analytics; \
    cd /opt/android/; \
    git clone https://github.com/cake-tech/cake_wallet/;

RUN set -ex; \ 
    cd /opt/android/cake_wallet/; \
    git checkout v4.4.0; \
    cd /opt/android/cake_wallet/scripts/android/; \
    ./install_ndk.sh;

ENV PATH=/home/appuser/app/sdk/flutter/bin/:$PATH
WORKDIR /opt/android/cake_wallet/scripts/android/

Build container with command podman build --pull --rm -t cakewallet_build_apk -f ContainerFile Run container with command podman run --rm --name cakewallet_build_apk -ti cakewallet_build_apk In container run commands:

source ./app_env.sh cakewallet;
./app_config.sh;
./build_all.sh;
./copy_monero_deps.sh;
cd /opt/android/cake_wallet/;
/home/appuser/app/sdk/flutter/bin/flutter pub get;
/home/appuser/app/sdk/flutter/bin/flutter packages pub run tool/generate_new_secrets.dart;
keytool -genkey -v -keystore $HOME/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias cake_alias -storepass cake_alias -keypass cake_alias -dname CN=IL;
/home/appuser/app/sdk/flutter/bin/flutter packages pub run tool/generate_android_key_properties.dart keyAlias=cake_alias storeFile=$HOME/key.jks storePassword=cake_alias keyPassword=cake_alias;
/home/appuser/app/sdk/flutter/bin/flutter packages pub run tool/generate_localization.dart;
cd cw_core && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. ;
cd cw_monero && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. ;
cd cw_bitcoin && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. ;
cd cw_haven && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. ;
/home/appuser/app/sdk/flutter/bin/flutter packages pub run build_runner build --delete-conflicting-outputs;
/home/appuser/app/sdk/flutter/bin/flutter build apk --release;
Giszmo commented 1 year ago

How is progress on this? How can we compile this app?

ghost commented 4 months ago

Why was this issue closed without any investigation or explanation? I'm concerned that the APK was demonstrably NOT reproducible.

tuxpizza commented 4 months ago

Hi, was a mistake to close this issue without a resolution.... as this issue was from 2 years ago, the build guide has been updated since then and I believe this is what you need:

Generate mobx models for cw_haven:

cd cw_haven && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd ..

Please have a look the current build guide and try building the latest main or version tag: https://github.com/cake-tech/cake_wallet/blob/main/howto-build-android.md

For discussion on 1 to 1 binary reproduceability, https://github.com/cake-tech/cake_wallet/issues/112 and https://github.com/cake-tech/cake_wallet/issues/338 will still be open.

Let us know if you have any other build questions :smiley:

ghost commented 3 months ago

Thanks @tuxpizza

@emanuelb Even though the Cake team hasn't seemed too concerned about it in the last few years, for the sake of the larger community I hope this package can be reevaluated on WalletScrutiny!

xrviv commented 1 month ago

Cool. In relation to current attempts by WalletScrutiny to re-verify apps, I'm opening an issue for walletscrutiny.com again. Hopefully, this app can be verified.

xrviv commented 1 month ago

The issue is here: https://gitlab.com/walletscrutiny/walletScrutinyCom/-/issues/537

We have our plates full though - so if anybody would like to boost the spirit of Open Source, you are most welcome to build this app.

keraliss commented 1 month ago

Hi, I tried to build the latest version, 4.19.1 and ran into some errors.

FROM ubuntu:20.04

# Avoid prompts from apt
ENV DEBIAN_FRONTEND=noninteractive

# Install required packages
RUN apt-get update && apt-get install -y \
    wget \
    curl \
    unzip \
    automake \
    build-essential \
    file \
    pkg-config \
    git \
    python \
    libtool \
    libtinfo5 \
    cmake \
    openjdk-8-jre-headless \
    clang

# Install Android SDK and NDK
ENV ANDROID_SDK_ROOT /opt/android-sdk
ENV ANDROID_NDK_ROOT /opt/android-ndk
ENV ANDROID_HOME ${ANDROID_SDK_ROOT}
ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin:${ANDROID_SDK_ROOT}/platform-tools:${ANDROID_NDK_ROOT}

RUN mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools && \
    wget -q https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip -O android-sdk.zip && \
    unzip -q android-sdk.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools && \
    mv ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools ${ANDROID_SDK_ROOT}/cmdline-tools/latest && \
    rm android-sdk.zip && \
    yes | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platform-tools" "platforms;android-33" "build-tools;33.0.0" && \
    wget -q https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip -O android-ndk.zip && \
    unzip -q android-ndk.zip -d /opt && \
    mv /opt/android-ndk-r17c ${ANDROID_NDK_ROOT} && \
    rm android-ndk.zip

# Install Flutter
ENV FLUTTER_ROOT /opt/flutter
ENV PATH ${PATH}:${FLUTTER_ROOT}/bin

RUN git clone https://github.com/flutter/flutter.git -b stable ${FLUTTER_ROOT} && \
    flutter doctor

# Install rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# Set up working directory
WORKDIR /app

# Clone Cake Wallet repository with the specific tag
RUN git clone https://github.com/cake-tech/cake_wallet.git . && \
    git fetch --all --tags && \
    git checkout tags/v4.19.1

# Generate keystore file
RUN keytool -genkey -v -keystore /root/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key -storepass your_store_password -keypass your_key_password -dname "CN=Your Name, OU=Your Organizational Unit, O=Your Organization, L=Your City, S=Your State, C=Your Country Code"

# Remove pubspec.lock to avoid conflicts
RUN find . -name pubspec.lock -exec rm -f {} \;

# Modify pubspec.yaml to fix intl dependency issue (more flexible regex)
RUN find . -name pubspec.yaml -print -exec sed -i 's/intl:.*$/intl: 0.19.0/' {} \; && \
    echo "pubspec.yaml files updated" && \
    grep -R "intl: 0.19.0" . || echo "Failed to update intl version"

# Set environment variables for the build
ENV ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT}
ENV ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT}
ENV PATH=${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin:${ANDROID_SDK_ROOT}/platform-tools:${ANDROID_NDK_ROOT}

# Build Cake Wallet
RUN mkdir -p /opt/android && \
    cd scripts/android && \
    echo "Current directory: $(pwd)" && \
    ls -la && \
    ./install_ndk.sh && \
    bash -c "set -x && source ./app_env.sh cakewallet && \
    ./app_config.sh && \
    echo 'Content of build_haven.sh:' && cat build_haven.sh && \
    ./build_all.sh" && \
    cd ../../ && \
    flutter pub get && \
    flutter pub upgrade --major-versions && \
    flutter packages pub run tool/generate_new_secrets.dart && \
    flutter packages pub run tool/generate_android_key_properties.dart keyAlias=key storeFile=/root/key.jks storePassword=your_store_password keyPassword=your_key_password && \
    flutter packages pub run tool/generate_localization.dart && \
    ./model_generator.sh && \
    flutter build apk --release

# The APK will be located at /app/build/app/outputs/flutter-apk/app-release.apk

# Add SHA256 checksums for verification
RUN echo "4324fe3ee56762c012135884ff3ac99c7194ffaeabcb26d9359316fc2e0d1426  /app/build/app/outputs/flutter-apk/app-release.apk" > /app/checksums.txt && \
    sha256sum -c /app/checksums.txt

# Add release notes
RUN echo "Cake Wallet v4.19.1 Release Notes:" > /app/release_notes.txt && \
    echo "* Monero and Ethereum enhancements" >> /app/release_notes.txt && \
    echo "* Synchronization improvements" >> /app/release_notes.txt && \
    echo "* Exchange flow enhancements" >> /app/release_notes.txt && \
    echo "* Ledger improvements" >> /app/release_notes.txt && \
    echo "* Bug fixes" >> /app/release_notes.txt

This is the dockerfile i created. this follows the build instructions provided in the howto-build-android.md . I faced this error

Resolving dependencies...

Note: intl is pinned to version 0.19.0 by flutter_localizations from the flutter SDK.

See https://dart.dev/go/sdk-version-pinning for details.

Because cake_wallet depends on flutter_localizations from sdk which depends on intl 0.19.0, intl 0.19.0 is required.

So, because cake_wallet depends on intl ^0.18.0, version solving failed.

You can try the following suggestion to make the pubspec resolve:

* Try an upgrade of your constraints: flutter pub upgrade --major-versions

The command '/bin/sh -c mkdir -p /opt/android &&     cd scripts/android &&     ./install_ndk.sh &&     bash -c "source ./app_env.sh cakewallet &&     ./app_config.sh &&     ./build_all.sh" &&     cd ../../ &&     flutter pub get &&     flutter pub upgrade --major-versions &&     flutter packages pub run tool/generate_new_secrets.dart &&     flutter packages pub run tool/generate_android_key_properties.dart keyAlias=key storeFile=/root/key.jks storePassword=your_store_password keyPassword=your_key_password &&     flutter packages pub run tool/generate_localization.dart &&     ./model_generator.sh &&     flutter build apk --release' returned a non-zero code: 1

It is in my understanding a dependency conflict, which arises due to flutter_localizations requiring intl version 0.19.0, while cake_wallet depends on intl version ^0.18.0. This version conflict causes the resolution process to fail. I tried to fix this by manually finding and fixing the file:

# Remove pubspec.lock to avoid conflicts
RUN find . -name pubspec.lock -exec rm -f {} \;

# Modify pubspec.yaml to fix intl dependency issue (more flexible regex)
RUN find . -name pubspec.yaml -print -exec sed -i 's/intl:.*$/intl: 0.19.0/' {} \; && \
    echo "pubspec.yaml files updated" && \
    grep -R "intl: 0.19.0" . || echo "Failed to update intl version"

but sadly that didn't work. I also tried deleting the pubspec.lock so it can be generated later, but that also didn't work. Any idea or suggestion on what to do next on this?