ImageMagick なる外部ライブラリーがありこれを使おうかと色々調べたがあまりAndroid C#で利用している情報が見つからず結果断念。

https://github.com/MolotovCherry/Android-ImageMagick7

 

代わりに ImageSharp を利用することに

Visual Stuido の NuGet より、SixLabors.ImageSharp を選択して、Version 1.0.4 を指定してダウンロード

(最新だと、netstandard2.0  をサポートしていない?)

Package より netstandard2.0 フォルダーより以下のファイルをAssets/Plugins に保存

SixLabors.ImageSharp.dll
System.Numerics.Vectors.dll
System.Buffers.dll
System.Runtime.CompilerServices.Unsafe.dll
System.Memory.dll
System.Text.Encoding.CodePages.dll

あとは、Android でビルド

以下が画像を変換するコード(楽ちん)

  // 色々な画像をPNGに変換 
    public static byte[] ConvertToPNG(byte[] imageData)
    {
        using (var image = SixLabors.ImageSharp.Image.Load(imageData)) {
            using (var outputStream = new MemoryStream()) {
                image.Save(outputStream, new PngEncoder());
                return outputStream.ToArray();
            }
        }
    }

iOS でももちろん動作します。

https://developers.google.com/cardboard/develop/unity/quickstart

 

Unity ver.2020.3.38

Mac ver.12.6

Android Sdk ver.30

 

Google Cardboard  のデモをAndroid 用にビルドしたら以下のエラー

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:3:5-94: AAPT: error: resource android:color/system_neutral1_1000 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:4:5-94: AAPT: error: resource android:color/system_neutral1_900 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:5:5-93: AAPT: error: resource android:color/system_neutral1_0 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:6:5-94: AAPT: error: resource android:color/system_neutral1_800 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:7:5-94: AAPT: error: resource android:color/system_neutral1_700 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:8:5-94: AAPT: error: resource android:color/system_neutral1_600 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:9:5-94: AAPT: error: resource android:color/system_neutral1_500 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:10:5-94: AAPT: error: resource android:color/system_neutral1_400 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:11:5-94: AAPT: error: resource android:color/system_neutral1_300 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:12:5-94: AAPT: error: resource android:color/system_neutral1_200 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:13:5-94: AAPT: error: resource android:color/system_neutral1_100 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:14:5-93: AAPT: error: resource android:color/system_neutral1_50 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:15:5-93: AAPT: error: resource android:color/system_neutral1_10 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:16:5-102: AAPT: error: resource android:color/system_neutral2_1000 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:17:5-102: AAPT: error: resource android:color/system_neutral2_900 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:18:5-101: AAPT: error: resource android:color/system_neutral2_0 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:19:5-102: AAPT: error: resource android:color/system_neutral2_800 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:20:5-102: AAPT: error: resource android:color/system_neutral2_700 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:21:5-102: AAPT: error: resource android:color/system_neutral2_600 not found.

/Users/falco/.gradle/caches/transforms-2/files-2.1/a0ebba694f8e6a95bc427eaef4894530/material-1.6.1/res/values-v31/values-v31.xml:22:5-102: AAPT: error: resource android:color/system_neutral2_500 not found.

リソースが見つからない…

 

対応としては、ライブラリーをダウングレード

// implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
// implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.protobuf:protobuf-javalite:3.19.4'

implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'

これでビルド出来た。

ConstraintLayout の基本的な考え方

<android.support.design.button.MaterialButton
    android:id="@+id/button1"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="1"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@id/button2" 
/>

layout_constraintBottom_toTopOf=”@id/button2″ は

@+id/button1 の constraintBottom を @id/button2 の toTop に合わせる

 

Unity で Android エミュレータを使用するとき、Android studio を起動するのが、ちょっとじゃまなので、コマンドラインからエミュレータを起動

% jdk 1.8
/usr/libexec/java_home -v1.8
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (Temurin)(build 25.302-b08, mixed mode)
// alias setting
% alias emulator="$ANDROID_HOME/emulator/emulator"
// name list show
% emulator -list-avds
Pixel_4_XL_API_21
Pixel_4_XL_API_23
Pixel_4_XL_API_25
Pixel_4_XL_API_27
Pixel_5_API_32
Pixel_5_API_33
// execute emulator @name
% emulator @Pixel_4_XL_API_23

 

Android のフレームワークの処理を確認したい時に必要な環境

  • Android エミューレータ
  • Source for Android
  • Google Apis * System image [Google play * System image ではない]

上記の環境を Android SDK よりダウンロードして、エミュレーターを起動

Android Studio の [Attach Debugger to Android Process] をクリック

[Show all processes] をチェック

[Create New] を選択、[system_process] を選択して [OK] をクリック

後は、普通のデバックと同様に、フレームワークのソースを参照出来るしブレイクポイントを設定出来ます。

※重要なのは「Google Apis * System image」を使用する事です。

Google play * System image を使用すると、[Show all processes]  チェックしても[system_process] は表示されません。

 

java.lang.IllegalStateException: Pre-packaged database has an invalid schema: WORDS(mobile.falco.EnglishTrainer.db.model.Words).
 Expected:
TableInfo{name='WORDS', columns={average=Column{name='average', type='INTEGER', affinity='3', notNull=notNull, primaryKeyPosition=0, defaultValue='0'}, ngCount=Column{name='ngCount', type='INTEGER', affinity='3', notNull=notNull, primaryKeyPosition=0, defaultValue='0'}, japanese=Column{name='japanese', type='TEXT', affinity='2', notNull=notNull, primaryKeyPosition=0, defaultValue='null'}, english=Column{name='english', type='TEXT', affinity='2', notNull=notNull, primaryKeyPosition=0, defaultValue='null'}, kigou=Column{name='kigou', type='TEXT', affinity='2', notNull=notNull, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='INTEGER', affinity='3', notNull=notNull, primaryKeyPosition=1, defaultValue='null'}, ipa=Column{name='ipa', type='TEXT', affinity='2', notNull=notNull, primaryKeyPosition=0, defaultValue='null'}, okCount=Column{name='okCount', type='INTEGER', affinity='3', notNull=notNull, primaryKeyPosition=0, defaultValue='0'}}, foreignKeys=[], indices=[]}
 Found:
TableInfo{name='WORDS', columns={}, foreignKeys=[], indices=[]}
    at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.kt:159)
    at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.kt:128)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:326)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:432)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:321)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableOrReadableDatabase(FrameworkSQLiteOpenHelper.java:273)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.innerGetDatabase(FrameworkSQLiteOpenHelper.java:225)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase(FrameworkSQLiteOpenHelper.java:183)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:133)
    at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.kt:71)
    at androidx.room.RoomDatabase.inTransaction(RoomDatabase.kt:634)
    at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.kt:430)

Android11 で実行すると上記のエラーとなる。

Android6 では問題なし。

database = Room.databaseBuilder(applicationContext, AppDatabase::class.java, "hatuon_.db")
    // .fallbackToDestructiveMigration()
    .createFromAsset("database/hatuon.db")
    .allowMainThreadQueries()
    .setJournalMode(RoomDatabase.JournalMode.TRUNCATE)
    .build()

database の名称を huton.db -> hatuon_.db にすることで正常に起動

development build を on にする

上記の設定で adb shell の run-as package-name が使えるようになる。

 

Flipper を使ってみたら結構便利だった。

List<SharedPreferencesDescriptor> descriptors = new ArrayList<SharedPreferencesDescriptor>();
descriptors.add(new SharedPreferencesDescriptor("prefs", MODE_PRIVATE));
descriptors.add(new SharedPreferencesDescriptor("myPrefs",MODE_PRIVATE));

client.addPlugin(new SharedPreferencesFlipperPlugin(this, descriptors));

 

Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class io.netty.channel.epoll.AbstractEpollChannel found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$1 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$2 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$1 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$2 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$3 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class io.netty.channel.epoll.AbstractEpollChannel found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$1 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$2 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$1 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$2 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$3 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class io.netty.channel.epoll.AbstractEpollChannel found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$1 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$2 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$1 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$2 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
     Duplicate class io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$3 found in modules jetified-netty-transport-native-epoll-4.1.67-linux-x86_64.Final-linux-x86_64 (io.netty:netty-transport-native-epoll:4.1.67.Final) and jetified-netty-transport-native-epoll-4.1.67.Final (io.netty:netty-transport-native-epoll:4.1.67.Final)
:
:
:
:
:
:

 

対応方法は以下

build.gradle

implementation( group: 'io.appium', name: 'java-client', version: '8.0.0-beta') {
    exclude group: 'io.netty', module: 'netty-transport-native-epoll'
    exclude group: 'io.netty', module: 'netty-transport-native-kqueue'
    exclude group: 'commons-logging', module: 'commons-logging'
}

基本的な考え方

io.netty:netty-transport-native-epoll

Dupulicate したグループとモジュールを指定して取り除く

group: io.netty

module : netty-transport-native-epoll

appium desktop を起動してサーバを起動

appium inspector を起動

iOS

{
  "platformName": "iOS",
  "appium:udid": "0943D45A-B772-4C36-B738-2931C093D6F1",
  "appium:deviceName": "iPhone",
  "appium:platformVersion": "15"
}

Android

{
  "platformName": "Android"
}

© 2023 Falco Tech Blog Suffusion theme by Sayontan Sinha