質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Gradle

Gradleは、ビルド自動化ツールです。 ソフトウェアパッケージやドキュメント、 または実際に何か他の種類のプロジェクトの構築、テスト、公開、展開などを自動化が出来ます

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

1回答

999閲覧

Androidでminioにファイルをアップロードしたい

log.suzaki

総合スコア2

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Gradle

Gradleは、ビルド自動化ツールです。 ソフトウェアパッケージやドキュメント、 または実際に何か他の種類のプロジェクトの構築、テスト、公開、展開などを自動化が出来ます

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2023/02/07 11:49

実現したいこと

Androidアプリでminioのサーバにファイルをアップロードしたい.

前提

AWSのライブラリを使用するのが正しいのかminioのライブラリを使用するのが正しいのかがわからないので両方トライしています.
この質問はminioのライブラリを使用する方の質問です.
以下を参考にコードを書いています.
https://min.io/docs/minio/linux/developers/java/minio-java.html

AWSの方でもエラーが発生しています.それはこの質問になっています.
https://teratail.com/questions/pp8nd2seajfu2w

発生している問題・エラーメッセージ

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher Process: com.example.s3client, PID: 13228 java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/stream/XMLInputFactory; at org.simpleframework.xml.stream.StreamProvider.<init>(StreamProvider.java:61) at org.simpleframework.xml.stream.ProviderFactory.getInstance(ProviderFactory.java:38) at org.simpleframework.xml.stream.NodeBuilder.<clinit>(NodeBuilder.java:45) at org.simpleframework.xml.stream.NodeBuilder.read(NodeBuilder.java:71) at org.simpleframework.xml.core.Persister.read(Persister.java:562) at org.simpleframework.xml.core.Persister.read(Persister.java:462) .....

該当のソースコード

kotlin

1package com.example.s3client 2 3import io.minio.MinioClient 4import io.minio.UploadObjectArgs 5 6class MinioClient { 7 8 val accessKey = "accessKey" 9 val secretKey = "secretKey" 10 val bucketName = "bucketName" 11 val endpoint = "endpoint" 12 13 fun postFile(pass: String) { 14 val minioClient = MinioClient.builder() 15 .endpoint(endpoint) 16 .credentials(accessKey, secretKey) 17 .build() 18 19 minioClient.uploadObject( 20 UploadObjectArgs.builder() 21 .bucket(bucketName) 22 .`object`("sample.csv") 23 .filename(pass) 24 .build() 25 ) 26 } 27}

試したこと

Failed resolution of: Ljavax/xml/stream/XMLInputFactory
このエラーはjavax.xml.streamパッケージが存在しないため発生していると思ったので.
implementation 'javax.xml.stream:stax-api:1.0-2'
これをimportしました.
しかしこれは以下のエラーを出します.

FATAL EXCEPTION: OkHttp Dispatcher Process: com.example.s3client, PID: 13955 javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72) at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)

このProvider com.bea.xml.stream.MXParserFactory not foundの対策として
implementation group: 'stax', name: 'stax-api', version: '1.0.1'
implementation group: 'stax', name: 'stax', version: '1.2.0'
を追加しました.
しかしこれは競合を起こしました.
なので最終的に

gradle

1 implementation 'androidx.core:core-ktx:1.9.0' 2 implementation 'androidx.appcompat:appcompat:1.6.0' 3 implementation 'com.google.android.material:material:1.8.0' 4 implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 5 testImplementation 'junit:junit:4.13.2' 6 androidTestImplementation 'androidx.test.ext:junit:1.1.5' 7 androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 8 implementation 'io.minio:minio:8.5.1' 9 implementation 'javax.xml.stream:stax-api:1.0-2' 10 implementation ('org.simpleframework:simple-xml:2.7.1'){ 11 exclude module: 'stax' 12 exclude module: 'stax-api' 13 exclude module: 'xpp3' 14 }

このようにしました.しかしこれは多くの競合のエラーを出します.

* What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable > Duplicate class org.simpleframework.xml.Attribute found in modules simple-xml-2.7.1 (org.simpleframework:simple-xml:2.7.1) and simple-xml-safe-2.7.1 (com.carrotsearch.thirdparty:simple-xml-safe:2.7.1) Duplicate class org.simpleframework.xml.Default found in modules simple-xml-2.7.1 (org.simpleframework:simple-xml:2.7.1) and simple-xml-safe-2.7.1 (com.carrotsearch.thirdparty:simple-xml-safe:2.7.1) Duplicate class org.simpleframework.xml.DefaultType found in modules simple-xml-2.7.1 (org.simpleframework:simple-xml:2.7.1) and simple-xml-safe-2.7.1 (com.carrotsearch.thirdparty:simple-xml-safe:2.7.1) Duplicate class org.simpleframework.xml.Element found in modules simple-xml-2.7.1 (org.simpleframework:simple-xml:2.7.1) and simple-xml-safe-2.7.1 (com.carrotsearch.thirdparty:simple-xml-safe:2.7.1) Duplicate class org.simpleframework.xml.ElementArray found in modules simple-xml-2.7.1 (org.simpleframework:simple-xml:2.7.1) and simple-xml-safe-2.7.1 (com.carrotsearch.thirdparty:simple-xml-safe:2.7.1) Duplicate class org.simpleframework.xml.ElementList found in modules simple-xml-2.7.1 (org.simpleframework:simple-xml:2.7.1) and simple-xml-safe-2.7.1 (com.carrotsearch.thirdparty:simple-xml-safe:2.7.1)

補足情報(FW/ツールのバージョンなど)

Android Studio Electric Eel | 2022.1.1 Patch 1

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

解決法

こいつをgradleに追加
implementation group: 'org.apache.openejb', name: 'javaee-api', version: '6.0-1'

で,こいつは他のライブラリが参照しているリソースを参照してしまうため
例(jetified-javaee-api-6.0-1.jarおよびjetified-geronimo-servlet_3.0_spec-1.0-sources.jar)が同じリソース
これを一つづつexcludeします.

packagingOptions {
pickFirst 'META-INF/services/javax.xml.stream.XMLInputFactory'
exclude 'javax/servlet/jsp/resources/jspxml.xsd'
exclude 'javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd'
exclude 'javax/servlet/jsp/resources/web-jsptaglibrary_2_1.xsd'
exclude 'javax/servlet/http/LocalStrings_ja.properties'
exclude 'META-INF/mimetypes.default'
exclude 'javax/servlet/resources/web-app_2_4.xsd'
exclude 'javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd'
exclude 'javax/servlet/resources/j2ee_web_services_client_1_1.xsd'
exclude 'javax/servlet/http/LocalStrings_fr.properties'
exclude 'javax/servlet/LocalStrings_ja.properties'
exclude 'javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd'
exclude 'javax/servlet/http/LocalStrings_es.properties'
exclude 'javax/servlet/resources/xml.xsd'
exclude 'javax/servlet/http/LocalStrings.properties'
exclude 'javax/servlet/resources/XMLSchema.dtd'
exclude 'javax/servlet/resources/j2ee_web_services_1_1.xsd'
exclude 'javax/servlet/resources/web-app_2_2.dtd'
exclude 'javax/servlet/resources/j2ee_1_4.xsd'
exclude 'META-INF/DEPENDENCIES'
exclude 'javax/servlet/resources/web-app_2_5.xsd'
exclude 'javax/el/LocalStrings.properties'
exclude 'javax/servlet/jsp/resources/jspxml.dtd'
exclude 'javax/servlet/resources/datatypes.dtd'
exclude 'javax/servlet/jsp/resources/jsp_2_0.xsd'
exclude 'javax/servlet/LocalStrings_fr.properties'
exclude 'javax/servlet/LocalStrings.properties'
exclude 'javax/servlet/jsp/resources/jsp_2_1.xsd'
exclude 'javax/servlet/resources/web-app_2_3.dtd'
}

するとOkHttpライブラリに関連する問題が発生します.
Requested factory com.ctc.wstx.stax.WstxInputFactory cannot be located

なのでWstxInputFactoryを追加します.
// https://mvnrepository.com/artifact/com.fasterxml.woodstox/woodstox-core
implementation 'com.fasterxml.woodstox:woodstox-core:6.5.0'

動きます.

gradle

1 2android { 3 packagingOptions { 4 exclude 'javax/servlet/jsp/resources/jspxml.xsd' 5 exclude 'javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd' 6 exclude 'javax/servlet/jsp/resources/web-jsptaglibrary_2_1.xsd' 7 exclude 'javax/servlet/http/LocalStrings_ja.properties' 8 exclude 'META-INF/mimetypes.default' 9 exclude 'javax/servlet/resources/web-app_2_4.xsd' 10 exclude 'javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd' 11 exclude 'javax/servlet/resources/j2ee_web_services_client_1_1.xsd' 12 exclude 'javax/servlet/http/LocalStrings_fr.properties' 13 exclude 'javax/servlet/LocalStrings_ja.properties' 14 exclude 'javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd' 15 exclude 'javax/servlet/http/LocalStrings_es.properties' 16 exclude 'javax/servlet/resources/xml.xsd' 17 exclude 'javax/servlet/http/LocalStrings.properties' 18 exclude 'javax/servlet/resources/XMLSchema.dtd' 19 exclude 'javax/servlet/resources/j2ee_web_services_1_1.xsd' 20 exclude 'javax/servlet/resources/web-app_2_2.dtd' 21 exclude 'javax/servlet/resources/j2ee_1_4.xsd' 22 exclude 'META-INF/DEPENDENCIES' 23 exclude 'javax/servlet/resources/web-app_2_5.xsd' 24 exclude 'javax/el/LocalStrings.properties' 25 exclude 'javax/servlet/jsp/resources/jspxml.dtd' 26 exclude 'javax/servlet/resources/datatypes.dtd' 27 exclude 'javax/servlet/jsp/resources/jsp_2_0.xsd' 28 exclude 'javax/servlet/LocalStrings_fr.properties' 29 exclude 'javax/servlet/LocalStrings.properties' 30 exclude 'javax/servlet/jsp/resources/jsp_2_1.xsd' 31 exclude 'javax/servlet/resources/web-app_2_3.dtd' 32 33 } 34 35} 36 37dependencies { 38 39 implementation 'androidx.core:core-ktx:1.9.0' 40 implementation 'androidx.appcompat:appcompat:1.6.0' 41 implementation 'com.google.android.material:material:1.8.0' 42 implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 43 testImplementation 'junit:junit:4.13.2' 44 androidTestImplementation 'androidx.test.ext:junit:1.1.5' 45 androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 46 implementation 'io.minio:minio:8.5.1' 47 implementation group: 'org.apache.openejb', name: 'javaee-api', version: '6.0-1' 48 // https://mvnrepository.com/artifact/com.fasterxml.woodstox/woodstox-core 49 implementation 'com.fasterxml.woodstox:woodstox-core:6.5.0' 50}

投稿2023/02/08 07:45

編集2023/02/08 07:46
log.suzaki

総合スコア2

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問