本文介绍了为不同架构生成APK - FFmpegMediaMetadataRetriever的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正忙着将 FFmpegMediaMetadataRetriever 预构建 .aar 文件添加到我的项目中,以减少每个架构的 Apk 文件大小.

我的问题:

  • 我应该将 .aar 文件按原样放置在我的 libs 文件夹中(而不为每个架构创建文件夹),还是应该将其添加到文件夹中?
  • - 我当前的版本是 21)?

他实现了这样的版本控制:

//映射给每个 ABI 一个值的版本代码.def abiCodes = ['x86':1,'x86_64':2,'armeabi-v7a':3,'arm64-v8a':4]//具有相同版本信息的同一个应用程序的 APK.android.applicationVariants.all { 变体 ->//为每个输出 APK 分配不同的版本代码.变体.输出.每个{输出 ->def abiName = output.getFilter(OutputFile.ABI)output.versionCodeOverride = abiCodes.get(abiName, 0) * 100000 + variant.versionCode}}

我正在寻找可能使用过 FFmpegMediaMetadataRetriever.aar 文件的人,他可以指导我如何正确实施它.

编辑 1

在了解更多有关不同架构/ABI 的信息后,我认为可以肯定地说如果我只包含 armeabi-v7a 那么大多数设备都会被覆盖"?(我的最低 sdk 是 16).

这是否意味着我不必拆分 APK 并且不必担心版本控制?

然后我可以正常导入 .aar - armv7-fmmr.aar 吗?

解决方案

您可以使用指定所需目标 ABI 的产品风格生成不同的 APK.然后,您可以根据每种产品风格指定要使用的 FMMR gradle 依赖项或独立的 AAR 文件.请参阅此 build.gradle 文件以供参考:

应用插件:'com.android.application'应用插件:'kotlin-android'应用插件:'kotlin-android-extensions'安卓 {compileSdkVersion 28默认配置{applicationId "com.wseemann.example"minSdk 版本 15目标SDK版本28版本代码 1版本名称1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}风味维度版本"产品风味{胖的 {ndk{abiFilters "armeabi", "armeabi-v7a", "x86", "mips", "x86_64", "arm64-v8a"}}armeabi {ndk{abiFilter "armeabi"}}armeabi_v7a {ndk{abiFilter "armeabi-v7a"}}x86 {ndk{abiFilter "x86"}}米普{ndk{abiFilter "mips"}}x86_64 {ndk{abiFilter "x86_64"}}arm64_v8a {ndk{abiFilter "arm64-v8a"}}}}依赖{实现文件树(目录:'libs',包括:['*.jar'])实现"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"实现 'com.android.support:appcompat-v7:28.0.0-rc01'实现 'com.android.support.constraint:constraint-layout:1.1.2'testImplementation 'junit:junit:4.12'androidTestImplementation 'com.android.support.test:runner:1.0.2'androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'//产品风味,特定于 ABI 的依赖项fatImplementation 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'armeabiImplementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-armeabi:1.0.14'armeabi_v7aImplementation'com.github.wseemann:FFmpegMediaMetadataRetriever-armeabi-v7a:1.0.14'x86Implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-x86:1.0.14'mipsImplementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-mips:1.0.14'x86_64Implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-x86_64:1.0.14'arm64_v8aImplementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-arm64-v8a:1.0.14'}

I'm busy adding FFmpegMediaMetadataRetriever pre-build .aar files to my project to reduce the Apk file size for each architecture.

This post added the following to his Gradle:

android {
splits {
        // Configures multiple APKs based on ABI.
        abi {
            // Enables building multiple APKs per ABI.
            enable true

            // By default all ABIs are included, so use reset() and include to specify that we only
            // want APKs for x86, armeabi-v7a, and mips.
            reset()

            // Specifies a list of ABIs that Gradle should create APKs for.
            include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"

            // Specifies that we want to also generate a universal APK that includes all ABIs.
            universalApk false
        }
    }
    //...    
}

The FFmpegMediaMetadataRetriever library provide the following .aar files:


My questions:

  • Should I place the .aar files in my libs folder as it is (without creating folders for each architecture), or should I add it in a folder?
  • - my current version is 21)?

He implemented versioning like this:

// Map for the version code that gives each ABI a value.
def abiCodes = ['x86':1, 'x86_64':2, 'armeabi-v7a':3, 'arm64-v8a':4]

// APKs for the same app that all have the same version information.
android.applicationVariants.all { variant ->
    // Assigns a different version code for each output APK.
    variant.outputs.each {
        output ->
            def abiName = output.getFilter(OutputFile.ABI)
            output.versionCodeOverride = abiCodes.get(abiName, 0) * 100000 + variant.versionCode
    }
}

I'm looking for someone that has perhaps used the .aar files of FFmpegMediaMetadataRetriever that can give me guidance on how to correctly implement it.

Edit 1

After learning more about different architectures/ABI's, I think it is safe to say that if I only include armeabi-v7a then most devices would be "covered"? (My minimum sdk is 16).

Does that then mean that I don't have to split the APK and I don't have to worry about versioning?

I can then just import the .aar - armv7-fmmr.aar as normal?

解决方案

You can generate different APK's using product flavors which specify the desired target ABI. You can then specify which FMMR gradle dependency or standalone AAR file to use depending on each product flavor. See this build.gradle file for reference:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.wseemann.example"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "version"
    productFlavors {
        fat {
            ndk {
                abiFilters "armeabi", "armeabi-v7a", "x86", "mips", "x86_64", "arm64-v8a"
            }
        }

        armeabi {
            ndk {
                abiFilter "armeabi"
            }
        }

        armeabi_v7a {
            ndk {
                abiFilter "armeabi-v7a"
            }
        }

        x86 {
            ndk {
                abiFilter "x86"
            }
        }

        mips {
            ndk {
                abiFilter "mips"
            }
        }

        x86_64 {
            ndk {
                abiFilter "x86_64"
            }
        }

        arm64_v8a {
            ndk {
                abiFilter "arm64-v8a"
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    // Product flavor, ABI specific dependencies
    fatImplementation 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
    armeabiImplementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-armeabi:1.0.14'
    armeabi_v7aImplementation'com.github.wseemann:FFmpegMediaMetadataRetriever-armeabi-v7a:1.0.14'
    x86Implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-x86:1.0.14'
    mipsImplementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-mips:1.0.14'
    x86_64Implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-x86_64:1.0.14'
    arm64_v8aImplementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-arm64-v8a:1.0.14'
}

这篇关于为不同架构生成APK - FFmpegMediaMetadataRetriever的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 18:44