为 Android 构建 Mailcore2

Build Mailcore2 for Android

我按照official build instractions重新编译库。就我而言:

> export ANDROID_SDK=$HOME/Library/Android/sdk
> export ANDROID_NDK=$ANDROID_SDK/ndk-bundle
> ./build.sh

并在编译过程中出现一些错误,例如:

[arm64-v8a] Compile++      : MailCore <= MCIMAPAsyncSession.cpp
In file included from /Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../include/MailCore/MCObject.h:11:0,
                 from /Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../include/MailCore/MCAutoreleasePool.h:5,
                 from /Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../include/MailCore/MCBaseTypes.h:5,
                 from /Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/async/imap/MCIMAPAsyncSession.h:13,
                 from /Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/async/imap/MCIMAPAsyncSession.cpp:9:
/Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/async/imap/MCIMAPAsyncSession.cpp: In member function 'virtual void mailcore::IMAPAsyncSession::automaticConfigurationDone(mailcore::IMAPSession*)':
/Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/async/imap/MCIMAPAsyncSession.cpp:874:87: warning: 'virtual mailcore::String* mailcore::IMAPSession::gmailUserDisplayName()' is deprecated (declared at /Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/core/imap/MCIMAPSession.h:196) [-Wdeprecated-declarations]
     MC_SAFE_REPLACE_COPY(String, mGmailUserDisplayName, session->gmailUserDisplayName());
                                                                                       ^
/Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../include/MailCore/MCUtils.h:8:27: note: in definition of macro 'MC_SAFE_COPY'
 #define MC_SAFE_COPY(o) ((o) != NULL ? (o)->copy() : NULL)
                           ^
/Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/async/imap/MCIMAPAsyncSession.cpp:874:5: note: in expansion of macro 'MC_SAFE_REPLACE_COPY'
     MC_SAFE_REPLACE_COPY(String, mGmailUserDisplayName, session->gmailUserDisplayName());
     ^
/Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/async/imap/MCIMAPAsyncSession.cpp:874:87: warning: 'virtual mailcore::String* mailcore::IMAPSession::gmailUserDisplayName()' is deprecated (declared at /Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/core/imap/MCIMAPSession.h:196) [-Wdeprecated-declarations]
     MC_SAFE_REPLACE_COPY(String, mGmailUserDisplayName, session->gmailUserDisplayName());
                                                                                       ^
/Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../include/MailCore/MCUtils.h:8:41: note: in definition of macro 'MC_SAFE_COPY'
 #define MC_SAFE_COPY(o) ((o) != NULL ? (o)->copy() : NULL)
                                         ^
/Users/nikolay/Documents/Mailcore/mailcore2/build-android/jni/../../src/async/imap/MCIMAPAsyncSession.cpp:874:5: note: in expansion of macro 'MC_SAFE_REPLACE_COPY'
     MC_SAFE_REPLACE_COPY(String, mGmailUserDisplayName, session->gmailUserDisplayName());
     ^

... compiling goes ok...
... and again some errors...

等等。最后我得到:

[arm64-v8a] StaticLibrary  : libstdc++.a
[arm64-v8a] SharedLibrary  : libMailCore.so
[arm64-v8a] Install        : libMailCore.so => libs/arm64-v8a/libMailCore.so
warning: [options] bootstrap class path not set in conjunction with -source 1.6
com/libmailcore/MainThreadUtils.java:3: error: package android.os does not exist
import android.os.Handler;
                 ^
com/libmailcore/MainThreadUtils.java:4: error: package android.os does not exist
import android.os.Looper;
                 ^
com/libmailcore/MainThreadUtils.java:5: error: package android.util does not exist
import android.util.Log;
                   ^
com/libmailcore/MainThreadUtils.java:10: error: cannot find symbol
    private Handler handler;
            ^
  symbol:   class Handler
  location: class MainThreadUtils
com/libmailcore/MainThreadUtils.java:21: error: cannot find symbol
        handler = new Handler(Looper.getMainLooper());
                      ^
  symbol:   class Handler
  location: class MainThreadUtils
com/libmailcore/MainThreadUtils.java:21: error: cannot find symbol
        handler = new Handler(Looper.getMainLooper());
                              ^
  symbol:   variable Looper
  location: class MainThreadUtils
6 errors
1 warning

如何重新编译库?最后我想修复一个 text relocations error 但它甚至没有建立一个干净的构建

它正在寻找 Android 平台 16 和 21,但找不到它们,这就是它显示错误消息的原因:

error: package android.os does not exist

这些通常安装在文件夹中 $ANDROID_SDK/platforms

(将其添加到 build-android/build.sh 的顶部附近,以查看它在做什么:

set -v
set -x

这将显示它的命令 运行,以及 shell 变量的内容。)

如果您在 Mailcore2 中打开文件 build-android/build.sh,您将看到如下行:

# Start building.
ANDROID_PLATFORM=android-16
archs="armeabi armeabi-v7a x86"

android-16 替换为您安装的任何版本,或者更好的是,安装 android-16 因为它期望如此。 此外,armeabi 平台支持已从最新的 Android NDK 中删除,这给我带来了错误。所以删除 armeabi 只留下 armeabi-v7ax86.

再往下还有:

ANDROID_PLATFORM=android-21
archs="arm64-v8a"

和:

ANDROID_PLATFORM=android-16
cd "$current_dir/../src/java"
...

所以安装android-16android-21最容易解决这个问题。

我也遇到了错误:

Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-16. 

找到这一行:

$ANDROID_NDK/ndk-build TARGET_PLATFORM=$ANDROID_PLATFORM TARGET_ARCH_ABI=$TARGET_ARCH_ABI \

并向其中添加 APP_PLATFORM,修复了该错误:

$ANDROID_NDK/ndk-build TARGET_PLATFORM=$ANDROID_PLATFORM APP_PLATFORM=$ANDROID_PLATFORM TARGET_ARCH_ABI=$TARGET_ARCH_ABI \

我也遇到了错误:

*** Android NDK: Invalid NDK_TOOLCHAIN_VERSION value: 4.9. GCC is no longer supported. See https://android.googlesource.com/platform/ndk/+/master/docs/ClangMigration.md.    .  Stop.

显然不再支持 GCC。我安装了 clang,然后它继续编译项目,但因另一个错误而停止。

此外,我不得不删除包含以下内容的行:

NDK_TOOLCHAIN_VERSION=4.9 \

如所述here

我收到错误:

MailCore2/build-android/jni/../../src/java/TypesUtils.cpp:84:32: error: member access into incomplete type 'const std::type_info'
MCLog("info name: %s", info->name());
                           ^

这显然与 this issue 有关:

GCC 似乎隐式声明了 std::type_info。在使用 Clang 和 libstdc++ 执行典型的 Hello World 时,您通常会在第一次遇到这个问题。 – Xeo 2013 年 2 月 26 日 20:42

我还不能解决这个问题,但我会在有机会的时候更新这个post。