为Android构建Mailcore2

时间:2018-04-10 14:49:18

标签: android android-ndk mailcore2

我按照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,但它甚至没有做出干净的构建

1 个答案:

答案 0 :(得分:1)

它正在寻找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 13年2月26日在20:42

我尚无法解决此问题,但有机会我会更新这篇文章。