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"
}

Appuim で Android のスクリーンキャプチャーを取るには?

index.js

const driver = require("webdriverio");
const assert = require("assert");

const opts = {
  path: '/wd/hub',
  port: 4723,
  capabilities: {
    platformName: "Android",
    platformVersion: "12",
    deviceName: "Android Emulator",
    app: "/Users/falco/Downloads/ApiDemos-debug.apk",
    appPackage: "io.appium.android.apis",
    appActivity: ".view.TextFields",
    automationName: "UiAutomator2"
  }
};


async function main () {
  const client = await driver.remote(opts);
  await pauseSec(5)

  // Screen shot を取る
  client.saveScreenshot("first.png");

  const field = await client.$("android.widget.EditText");
  await field.setValue("Hello World!");
  await pauseSec(5)
  await field.setValue("Hello World!!!!!!");
  const value = await field.getText();
  assert.strictEqual(value,"Hello World!");

  await pauseSec(5)


  await client.deleteSession();
}

async function pauseSec(timeSec) {
  console.log("Start pauseSec")
  await new Promise(r => setTimeout(r, timeSec * 1000));
  console.log("End")
}

main();

node index.js

デモ用アプリ

https://github.com/appium/appium/raw/master/sample-code/apps/ApiDemos-debug.apk

adbc.sh

#!/bin/bash
FILE_NAME=`date +%Y%m%d_%H_%M_%S`.png
echo $FILE_NAME

adb shell screencap -p /sdcard/$FILE_NAME
adb pull /sdcard/$FILE_NAME
adb shell rm /sdcard/$FILE_NAME

コマンドラインから実行して日時のファイル名でキャプチャーを取得する

build.gradle(app)

android {
    buildFeatures {
        viewBinding true
    }
}

使う時

class MainActivity : AppCompatActivity() {
    lateinit var bind : ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        bind = ActivityMainBinding.inflate(layoutInflater)
        init()
        setContentView(bind.root)
    }

    private fun init() {
        bind.button.setOnClickListener{
            Toast.makeText(this, "on click", Toast.LENGTH_LONG).show()
            bind.textViewDice.text = "6"
        }
    }

}
findViewById は、もう不要、DataBinding より軽量でシンプル
Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NoClassDefFoundError: javax/annotation/Generated

gradle 7.0.2 JDK11

dagger2 を試そうとしたらエラー

 

解決策、以下を追加

dependencies {
    annotationProcessor 'javax.annotation:javax.annotation-api:1.3.2'
}

 

// ? null許容 (Nullable)
var a: String = "abc" // Regular initialization means non-null by default
a = null // compilation error

var b: String? = "abc" // can be set to null
b = null // ok


// ?. 安全呼び出し (Safe Call) 
val a = "Kotlin"
val b: String? = null
println(b?.length)
println(a?.length)	// 不必要な安全呼び出し


// !! Not-Null Assertion Operator
// Nullableな変数を強制的にNon-Nullに変換。もし変数がnullだった場合は、例外が発生するので注意
// NPE-lovers の為の演算子? Null の時は、例外を発生させたいと言う強い意志を持って使う
var a: Int? = 1
a = null
val b = a!!.toString()
// java.lang.NullPointerException


// ?: エルビス演算子(Elvis Operator)
var a: String? = "Hello"
a = null
val b: String = a ?: "1234567890"
println(b?.length)	// print 10

 

# キャプチャー
adb shell screencap -p /sdcard/screen.png

# ファイル取得
adb pull /sdcard/screen.png

# デバイス一覧
adb devices

# デバイス指定
adb -s [deviceId] pull /sdcard/screen.png

# インストール
adb install package.apk

# アンインストール
adb uninstall package.name

# パッケージ情報の取得
adb shell dumpsys package package.name

# 現在表示されてる Activity の取得
adb shell dumpsys window | grep mCurrentFocus
mCurrentFocus=Window{6f7463b u0 com.example.mybottombar/com.example.mybottombar.MainActivity}

# データ削除
adb shell pm clear package.name

# adb Wifi 接続
# 192.168.10.104 はAndroid端末のIPアドレス
adb tcpip 5555
adb connect 192.168.10.104

https://developer.android.com/studio/command-line/adb?hl=ja

 
 

 

 

© 2024 Falco Tech Blog Suffusion theme by Sayontan Sinha