为 Android 构建 Mailcore2

Posted

技术标签:

【中文标题】为 Android 构建 Mailcore2【英文标题】:Build Mailcore2 for Android 【发布时间】:2018-09-20 06:05:12 【问题描述】:

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

【问题讨论】:

在哪里添加这个: > export ANDROID_SDK=$HOME/Library/Android/sdk > export ANDROID_NDK=$ANDROID_SDK/ndk-bundle > ./build.sh 我无法进行此设置。请帮帮我 【参考方案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 2013 年 2 月 26 日 20:42

我还不能解决这个问题,但我会在有机会时更新这篇文章。

【讨论】:

很好的研究! :) @NikolayKulachenko 谢谢,有空我会努力完成的。

以上是关于为 Android 构建 Mailcore2的主要内容,如果未能解决你的问题,请参考以下文章

为 Android 构建 QtLocation 模块

Android - 为不同的处理器架构构建单独的 APK

在 Eclipse 中构建 Android 项目 android.support 无法解析为类型

使用 librtmp 为 android 构建 FFMPEG

使用 androiddeployqt 为 android 构建 Qt 应用程序时出现 Gradle 构建错误

为 Android 构建 MUPDF