如果支持多个ABI,AndroidStudio每次都会重建所有内容 [英] AndroidStudio rebuilds everything every time if multiple ABIs are supported

查看:83
本文介绍了如果支持多个ABI,AndroidStudio每次都会重建所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我为一个ABI构建我的AndroidStudio,它会按预期工作.

If I build my AndroidStudio for one ABI, it works as expected.

如果我支持两个ABI,例如说' armeabi-v7a '和' arm64-v8a ',那么Android Studio每次都会重建每个文件,即使没什么改变.

If I support two ABIs, say for 'armeabi-v7a' and 'arm64-v8a', then Android Studio will rebuild every file, every time, even if nothing changed.

我将CMake外部版本用于我的应用程序的本机部分.

I use CMake external build to for the native part of my app.

我的成绩文件:

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.steenriver.biplane"
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 115
        versionName "1.15"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        ndk {
            //abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
            abiFilters 'armeabi-v7a', 'arm64-v8a'
            //abiFilters 'arm64-v8a'
            //abiFilters 'armeabi-v7a'
        }
        externalNativeBuild {
            cmake {
                //ldFlags "-Wl,-fuse-ld=gold"
                cppFlags "-std=c++11 -DANDROID=1 -DPLAY=1 -DUSEES3=1 -DLOGTAG=biplane"
                arguments "-DCMAKE_VERBOSE_MAKEFILE=1", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_ARM_MODE=arm"
            }
        }

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            externalNativeBuild {
                cmake {
                    cppFlags += "-DDEBUG -DSHOWGRAPHS"
                }
            }
        }
    }
    externalNativeBuild {
        cmake {
            path '../jni/CMakeLists.txt'
        }
    }
}

还有我的顶级CMakeLists.txt:

And my top level CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)


# dependency: dblunt


set( dblunt_src_DIR $ENV{HOME}/src/dutch-blunt/src )
set( dblunt_build_DIR $ENV{HOME}/src/dutch-blunt/src/output )
file(MAKE_DIRECTORY ${dblunt_build_DIR})
add_subdirectory( ${dblunt_src_DIR} ${dblunt_build_DIR} )


# dependency: GBase

set( gbase_src_DIR $ENV{HOME}/apps/GBase/src )
set( gbase_build_DIR $ENV{HOME}/apps/GBase/src/output )
file(MAKE_DIRECTORY ${gbase_build_DIR})
add_subdirectory( ${gbase_src_DIR} ${gbase_build_DIR} )


# dependency: PI

set( pi_src_DIR ../../PI )
set( pi_build_DIR ../../PI/output )
file(MAKE_DIRECTORY ${pi_build_DIR})
add_subdirectory( ${pi_src_DIR} ${pi_build_DIR} )


# dependency uif
set( uif_src_DIR ../../../uif )
set( uif_build_DIR ../../../uif/output )
file(MAKE_DIRECTORY ${uif_build_DIR})
add_subdirectory( ${uif_src_DIR} ${uif_build_DIR} )


# dependency gpgoap
set( gpgoap_src_DIR $ENV{HOME}/src/GPGOAP )
set( gpgoap_build_DIR $ENV{HOME}/src/GPGOAP/output )
file(MAKE_DIRECTORY ${gpgoap_build_DIR})
add_subdirectory( ${gpgoap_src_DIR} ${gpgoap_build_DIR} )


# dependency: OpenDE
set( opende_src_DIR $ENV{HOME}/src/opende )
set( opende_build_DIR $ENV{HOME}/src/opende/output )
file(MAKE_DIRECTORY ${opende_build_DIR})
add_subdirectory( ${opende_src_DIR} ${opende_build_DIR} )


# dependency: OpenAL
set( openal_src_DIR $ENV{HOME}/src/openal-soft/jni )
set( openal_build_DIR $ENV{HOME}/src/openal-soft/jni/output )
file(MAKE_DIRECTORY ${openal_build_DIR})
add_subdirectory( ${openal_src_DIR} ${openal_build_DIR} )


# dependency: freealut
set( freealut_src_DIR $ENV{HOME}/src/freealut/src )
set( freealut_build_DIR $ENV{HOME}/src/freealut/src/output )
file(MAKE_DIRECTORY ${freealut_build_DIR})
add_subdirectory( ${freealut_src_DIR} ${freealut_build_DIR} )


# depencency: gpg (prebuilt, provided by Google)

add_library( gpg
             STATIC
             IMPORTED
)
set_target_properties( gpg
        PROPERTIES IMPORTED_LOCATION
        $ENV{HOME}/src/gpg-cpp-sdk/android/lib/gnustl/${ANDROID_ABI}/libgpg.a )


set ( CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=gold ${CMAKE_SHARED_LINKER_FLAGS}" )

# now build app's shared lib
add_library(biplane SHARED
    main.cpp
    StateManager.cpp
    scorekeeper.cpp
)

target_include_directories(biplane PRIVATE
    $ENV{HOME}/src/gpg-cpp-sdk/android/include
    $ENV{HOME}/apps/GBase/src
    $ENV{HOME}/apps/GBase/src/Android
    $ENV{HOME}/src/stb
    ../../PI
    .
)

# add lib dependencies
target_link_libraries(biplane
    gpg
    pi
    uif
    gbase
    dblunt
    gpgoap
    opende
    freealut
    openal
    EGL
    GLESv3
    OpenSLES
    android
    log
    z
    m
)

如何说服Android Studio仅重新编译已更改的文件?

How can I convince Android Studio to recompile only the files that changed?

推荐答案

这是由于所有版本的.o文件都具有相同的输出目录这一事实引起的.

This was caused by the fact that the build variants all had the same output directory for the .o files.

您需要将构建目录拆分为release/debug和不同的ABI.

You need to split out the build directory into release/debug and into the different ABIs.

执行此操作的方法是使用 CMAKE_CURRENT_BINARY_DIR 宏,如下所示:

The way to do this, is by using the CMAKE_CURRENT_BINARY_DIR macro as such:

set( gpgoap_src_DIR $ENV{HOME}/src/GPGOAP )
add_subdirectory( ${gpgoap_src_DIR} ${CMAKE_CURRENT_BINARY_DIR}/gpgoap )

如果执行此操作,则arm7调试目标文件将最终位于: app/.externalNativeBuild/cmake/debug/armeabi-v7a,因此它们不会与其他ABI发生冲突.

If you do this, then the arm7 debug object files will end up in: app/.externalNativeBuild/cmake/debug/armeabi-v7a so they will not clash with other ABIs.

请注意,您无法重复使用输出目录,因此您需要为每个add_subdirectory()后缀它们.

Note that you cannot re-use output directories, so you do need to postfix them for each add_subdirectory() that you do.

最后一句话: cmake文档说输出目录对于add_subdirectory()是可选的,但我发现并非如此.您需要至少提供两个参数.

One final remark: the cmake documentation says that the output directory is optional for add_subdirectory() but I found this not to be the case. You need to supply it at least two arguments.

这篇关于如果支持多个ABI,AndroidStudio每次都会重建所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆