0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

DJIのサンプルプログラムGSDemoのSDKバージョンを4.16.1にしてエラーが出るときの対処法

Last updated at Posted at 2022-06-06

DJI Mobile SDKを学ぶうちにGSDemoのアプリを動かすことになった.今回タイトルのような事態となったので対処法を調べた.
公式のサンプルではSDKが4.15となっており,現時点(2022年6月6日)で発表されているSDK4.16.1には対応していない.
今回4.16.1にバージョンをあげたときにエラーが出たので,自分が行った対処法を記録する.

実行環境

OS AndroidStudio
Windows 10 Home Bumblebee 2021.1.1 RC1

java.lang.RuntimeException: Manifest merger failed with multiple errors, see logsがでたとき

①AndroidManifest.xmlのMerged Manifestをクリックする(画像赤枠)

ManifestMergerFailed.png

②表示されるエラーを確認(画像赤枠)

MergeManifestError.png
今回はuses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in libraryと表示されていたのでModuleのbuild.gradleのminSdkVersionを変える

defaultConfig {
-       minSdkVersion 19
+       minSdkVersion 21
        targetSdkVersion 30
        multiDexEnabled true
        ndk {
            // On x86 devices that run Android API 23 or above, if the application is targeted with API 23 or
            // above, FFmpeg lib might lead to runtime crashes or warnings.
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
        multiDexEnabled true //Mention in the doc
    }

com.google.android.gms.internal.zzbglが見つからないといわれたとき

Moduleのbuild.gradleに追加

implementation 'com.google.android.gms:play-services-maps:18.0.2'

Failed resolution of: Lcom/google/android/gms/common/internal/zzbqがでたとき

Moduleのbuild.gradleに追加

implementation 'com.android.support:multidex:1.0.3'

Projectのbuild.gradleのallprojectsにsubprojectsを追加

allprojects {
    repositories {
        google()
        mavenCentral()
    }
+   subprojects {
+       project.configurations.all {
+           resolutionStrategy.eachDependency { details ->
+               if (details.requested.group == 'com.google.android.gms'
+                       && !details.requested.name.contains('multidex') ) {
+                   details.useVersion "12.0.1"
+               }
+           }
+       }
+   }
}

まとめ

最後に対処前と対処後のbuild.gradleの全文を載せる.
特に言及はしていないが,dependenciesの中に記述しているimplementationの中でimplementation 'com.google.android.gms:play-services:12.0.1'以外はバージョンを上げている.

対処前

build.gradle(Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
build.gradle(Module)
apply plugin: 'com.android.application'

repositories {
    mavenLocal()
}

android {
    compileSdkVersion 30
    buildToolsVersion '30.0.2'
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 30
        multiDexEnabled true
        ndk {
            // On x86 devices that run Android API 23 or above, if the application is targeted with API 23 or
            // above, FFmpeg lib might lead to runtime crashes or warnings.
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
        multiDexEnabled true //Mention in the doc
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        incremental = true
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }

    packagingOptions {
        doNotStrip "*/*/libdjivideo.so"
        doNotStrip "*/*/libSDKRelativeJNI.so"
        doNotStrip "*/*/libFlyForbid.so"
        doNotStrip "*/*/libduml_vision_bokeh.so"
        doNotStrip "*/*/libyuv2.so"
        doNotStrip "*/*/libGroudStation.so"
        doNotStrip "*/*/libFRCorkscrew.so"
        doNotStrip "*/*/libUpgradeVerify.so"
        doNotStrip "*/*/libFR.so"
        doNotStrip "*/*/libDJIFlySafeCore.so"
        doNotStrip "*/*/libdjifs_jni.so"
        doNotStrip "*/*/libsfjni.so"
        doNotStrip "*/*/libDJICommonJNI.so"
        doNotStrip "*/*/libDJICSDKCommon.so"
        doNotStrip "*/*/libDJIUpgradeCore.so"
        doNotStrip "*/*/libDJIUpgradeJNI.so"
        exclude 'META-INF/rxjava.properties'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.squareup:otto:1.3.8'
    implementation('com.dji:dji-sdk:4.15', {
        /**
         * Uncomment the "library-anti-distortion" if your app does not need Anti Distortion for Mavic 2 Pro and Mavic 2 Zoom.
         * Uncomment the "fly-safe-database" if you need database for release, or we will download it when DJISDKManager.getInstance().registerApp
         * is called.
         * Both will greatly reducing the size of the APK.
         */
        exclude module: 'library-anti-distortion'
        //exclude module: 'fly-safe-database'
    })
    compileOnly 'com.dji:dji-sdk-provided:4.15'

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.core:core:1.3.2'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.annotation:annotation:1.2.0'

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.13.2'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'com.google.android.gms:play-services:10.2.1'
    implementation 'com.google.android.gms:play-services-ads:10.2.1'
    implementation 'com.google.android.gms:play-services-auth:10.2.1'
    implementation 'com.google.android.gms:play-services-gcm:10.2.1'
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
}

対処後

build.gradle(Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.google.android.gms'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "12.0.1"
                }
            }
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
build.gradle(Module)
apply plugin: 'com.android.application'

repositories {
    mavenLocal()
}

android {
    compileSdkVersion 31
    buildToolsVersion '30.0.3'
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 31
        multiDexEnabled true  //Mention in the doc
        ndk {
            // On x86 devices that run Android API 23 or above, if the application is targeted with API 23 or
            // above, FFmpeg lib might lead to runtime crashes or warnings.
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        incremental = true
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }

    packagingOptions {
        doNotStrip "*/*/libdjivideo.so"
        doNotStrip "*/*/libSDKRelativeJNI.so"
        doNotStrip "*/*/libFlyForbid.so"
        doNotStrip "*/*/libduml_vision_bokeh.so"
        doNotStrip "*/*/libyuv2.so"
        doNotStrip "*/*/libGroudStation.so"
        doNotStrip "*/*/libFRCorkscrew.so"
        doNotStrip "*/*/libUpgradeVerify.so"
        doNotStrip "*/*/libFR.so"
        doNotStrip "*/*/libDJIFlySafeCore.so"
        doNotStrip "*/*/libdjifs_jni.so"
        doNotStrip "*/*/libsfjni.so"
        doNotStrip "*/*/libDJICommonJNI.so"
        doNotStrip "*/*/libDJICSDKCommon.so"
        doNotStrip "*/*/libDJIUpgradeCore.so"
        doNotStrip "*/*/libDJIUpgradeJNI.so"
        exclude 'META-INF/rxjava.properties'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.squareup:otto:1.3.8'
    implementation('com.dji:dji-sdk:4.16.1', {
        /**
         * Uncomment the "library-anti-distortion" if your app does not need Anti Distortion for Mavic 2 Pro and Mavic 2 Zoom.
         * Uncomment the "fly-safe-database" if you need database for release, or we will download it when DJISDKManager.getInstance().registerApp
         * is called.
         * Both will greatly reducing the size of the APK.
         */
        exclude module: 'library-anti-distortion'
        //exclude module: 'fly-safe-database'
    })
    compileOnly 'com.dji:dji-sdk-provided:4.16.1'

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'androidx.core:core:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.annotation:annotation:1.3.0'

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.13.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.gms:play-services-maps:18.0.2'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.google.android.gms:play-services-ads:21.0.0'
    implementation 'com.google.android.gms:play-services-auth:20.2.0'
    implementation 'com.google.android.gms:play-services-gcm:17.0.0'
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?