ros2

NodeJSでflvからmp4へのエンコード handbrake-jsインストールでエラー (public key is not available)

NodeJsでFlvからエンコードするケースがあったので、ffmpegではなくhandbreakでやってみようとnpmサイトをみながらインストール

handbrake-js
Handbrake-js is Handbrake (v1.1.2) for node.js, funnily enough. It aspires to provide a lean and stable foundation for building video transcoding software in node.js.

HandBrake is a tool for converting video from nearly any format to a selection of modern, widely supported codecs. It can process most common multimedia files and any DVD or BluRay sources that do not contain any copy protection.

https://www.npmjs.com/package/handbrake-js


sudo add-apt-repository --yes ppa:stebbins/handbrake-releases
sudo apt-get update -qq
sudo apt-get install -qq handbrake-cli

The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 23E7166788B63E1E

レポジトリ追加でエラーが発生


Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [183 kB]
Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [714 kB]
Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [6388 B]
Fetched 1900 kB in 4s (429 kB/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://dl.yarnpkg.com/debian stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 23E7166788B63E1E
W: Failed to fetch https://dl.yarnpkg.com/debian/dists/stable/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 23E7166788B63E1E

aptの証明書に設定


sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 23E7166788B63E1E
Executing: /tmp/apt-key-gpghome.pxI7v7yeEX/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 23E7166788B63E1E
gpg: key 1646B01B86E50310: "Yarn Packaging " 2 new signatures
gpg: key 1646B01B86E50310: "Yarn Packaging " 2 new subkeys

AdMobのリワード広告が出ない( onRewardedVideoAdLoaded Error Code = 3)

昨日まではテスト広告が表示されてたけど、今日はCode3になってしまう。

onRewardedVideoAdLoaded Code 3


     mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance( this );
     mRewardedVideoAd.setRewardedVideoAdListener( this );
     loadRewarded();
   }

    private void loadRewarded() {
        if( !mRewardedVideoAd.isLoaded() ) {
            mRewardedVideoAd.loadAd( getString( R.string.ad_reword ),
                    new AdRequest.Builder().addTestDevice( getResources().getString( R.string.test_device_id ) ).build() );
        }
    }

    @Override
        public void onRewardedVideoAdFailedToLoad( int errorCode ) {

addTestDeviceでテストデバイスを指定してるけど
試しに、下記の方法でコードをアプリIDはそのままで、リワードのコードを変更したら表示されるようになった。

リワードはaddTestDeviceだけじゃだめなのか?

テストには必ずテスト広告を使用する
アプリの開発中やテストの際は必ずテスト広告を使用し、実際の広告は使用しないでください。実際の広告を使用すると、アカウントの停止につながる可能性があります。
テスト広告を読み込むには、次に示す Android 動画リワード向けのテスト専用広告ユニット ID を使う方法が便利です。
ca-app-pub-3940256099942544/5224354917

https://developers.google.com/admob/android/rewarded-video

AdMobのバナーが表示されない(Android,Java,Admob)

AdMobが表示されない時にみてみる。


adView.setAdListener( new AdListener() {
            @Override
            public void onAdLoaded() {
            }
            @Override
            public void onAdFailedToLoad(int errorCode) {
                Log.i( "trouble-adMob-isGone", "onAdFailedToLoad errorCode => " + errorCode );
            }

エラーコードはAdRequestに定義されています。


public static final int ERROR_CODE_INTERNAL_ERROR = 0;
public static final int ERROR_CODE_INVALID_REQUEST = 1;
public static final int ERROR_CODE_NETWORK_ERROR = 2;
public static final int ERROR_CODE_NO_FILL = 3;

onAdFailedToLoad() メソッドは、パラメータが含まれる唯一のメソッドです。errorCode パラメータは、発生したエラーの種類を表します。値は AdRequest クラスで定数値として定義されます。
ERROR_CODE_INTERNAL_ERROR - 内部でエラーが発生している(広告サーバーから無効な応答を受け取った場合など)。
ERROR_CODE_INVALID_REQUEST - 広告リクエストが無効(広告ユニット ID が不適切だった場合など)。
ERROR_CODE_NETWORK_ERROR - ネットワーク接続が原因で広告をリクエストできなかった。
ERROR_CODE_NO_FILL - 広告リクエストは成功したものの、広告枠の不足が原因で広告が返されなかった。

com.mikepenz:materialdrawerをアップデートしたらAndroidXが必要になって予定外のSupport LibraryからのandroidX移行

AndroidStudioのリファクタリングからAndroidXへのマイグレーションはできますが
失敗したのか、よくわかりませんが
自分の場合はimportとXmlは手動で変えました。
ほんとはどこまで自動やってくれるんだろう。。


< android.support.v4.view.ViewPager
 xmlns:android="http://schemas.android.com/apk/res/android"

< androidx.viewpager.widget.ViewPager
 xmlns:android="http://schemas.android.com/apk/res/android"

https://developer.android.com/jetpack/androidx/migrate

Android Oでフォアグラウンドサービスがjava.lang.RuntimeException [Caused by: java.lang.SecurityExceptio at android.app.Service.startForeground]

Playコンソールでエラーを見つけた・・


java.lang.RuntimeException: 
  at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3698)
  at android.app.ActivityThread.access$1600 (ActivityThread.java:200)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1691)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:193)
  at android.app.ActivityThread.main (ActivityThread.java:6762)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)
Caused by: java.lang.SecurityException: 
  at android.os.Parcel.createException (Parcel.java:1950)
  at android.os.Parcel.readException (Parcel.java:1918)
  at android.os.Parcel.readException (Parcel.java:1868)
  at android.app.IActivityManager$Stub$Proxy.setServiceForeground (IActivityManager.java:5198)
  at android.app.Service.startForeground (Service.java:695)
  at com.doroidpanic.apps.service.xxyba.a (Xxyba.java:150)
  at com.doroidpanic.apps.service.xxyba.onStartCommand (Xxyba.java:102)
  at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3679)
Caused by: android.os.RemoteException: 
  at com.android.server.am.ActivityManagerService.enforcePermission (ActivityManagerService.java:9331)
  at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked (ActiveServices.java:1193)
  at com.android.server.am.ActiveServices.setServiceForegroundLocked (ActiveServices.java:874)
  at com.android.server.am.ActivityManagerService.setServiceForeground (ActivityManagerService.java:20597)
  at android.app.IActivityManager$Stub.onTransact (IActivityManager.java:976)

ここにあった。
https://developer.android.com/about/versions/pie/android-9.0-changes-28#fg-svc

パーミッションが足りてないのか


< uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

動作の変更点: API レベル 28+ をターゲットとするアプリ
Android 9(API レベル 28)では、Android システムにさまざまな変更が加えられています。 以下の動作の変更点は、API レベル 28 以降をターゲットとするアプリのみに適用されます。 targetSdkVersion を API レベル 28 以降に設定するアプリは、必要に応じてアプリを修正してこれらの動作を適切にサポートする必要があります。
Android 9 で実行されるすべてのアプリに影響を与える変更点については、ターゲットとする API レベルに関係なく、動作の変更点: すべてのアプリをご覧ください。
フォアグラウンド サービス
Android 9 以降をターゲットにするアプリは、フォアグラウンド サービスを使用する際に FOREGROUND_SERVICE パーミッションをリクエストする必要があります。 これは Normal パーミッションなので、リクエストしたアプリに自動で付与されます。

Android 9 以降をターゲットにするアプリが FOREGROUND_SERVICE をリクエストせずに、フォアグラウンド サービスの作成を試みると、システムにより、SecurityException がスローされます。

AndroidStudioからGitHubにリモートプッシュしたら [Push rejected: Push master to origin/master was rejected by remote] [remote: error: GH007: Your push would publish a private email address.]

既存のプロジェクトをAndroidStudioからGitHubにインポートはできましたが
ローカルのcommitをリモートへPushしようとしたらエラーが発生

Push rejected: Push master to origin/master was rejected by remote


Push rejected: Push master to origin/master was rejected by remote

ネットで調べて、pull origin masterしたけどダメだったので
プロジェクトディレクトリでターミナル開いてターミナルからGitコマンドを実行したら詳細なエラーがわかりました。

GH007: Your push would publish a private email address.


$git push origin master
Enumerating objects: 38, done.
Counting objects: 100% (38/38), done.
Delta compression using up to 8 threads
Compressing objects: 100% (16/16), done.
Writing objects: 100% (20/20), 2.37 KiB | 809.00 KiB/s, done.
Total 20 (delta 11), reused 0 (delta 0)
remote: Resolving deltas: 100% (11/11), completed with 11 local objects.
remote: error: GH007: Your push would publish a private email address.
remote: You can make your email public or disable this protection by visiting:
remote: http://github.com/settings/emails
To https://github.com/doroidpanic/test.git
 ! [remote rejected] master -> master (push declined due to email privacy restrictions)
error: failed to push some refs to 'https://github.com/doroidpanic/test.git'

GitHubのエラーコードGH007でした
Githubのアカウント設定で「Keep my email address private」なのに
そのメールアドレスが設定されているので止めてくれていたようです。

Commitに残るアドレスは


git config --global user.email

で確認できます。

GitHubにログインしてのメールアドレス設定のページにアクセスすると
「Primary email address」のところに自分の匿名?”@users.noreply.github.com”のメールアドレスが記載されています。
フォントの関係で見えにくいですが、説明文の中に@users.noreply.github.comがあります。

それをGitに設定しました。


 git config --global user.email  "@users.noreply.github.com"

ローカルコミットの取り消し


git reset --soft HEAD^

ターミナルでHeadしたら、AndroidStudio側の履歴も即反映されたので
もう一度コミットして詳細をみると、メールアドレスが@users.noreply.github.comになっています。
それから再度リモートプッシュしたら成功しました。


プッシュ成功: Pushed 1 commit to origin/master

https://github.com/settings/emails

なんだかんだ動いてたVMware Fusion 8.5.10がmacOS Mojave 10.14.2(18C54)にアップデートでやっと動作不具合

2018/12にmacOS Mojave 10.14.2の更新がきていたので、macbook Airを更新したら
YosemiteやHigh Sierra、macOS Mojaveでもなんだかんだ動作していたVMware Fusion 8.5.19が動かないというか
マウスやキーボードの操作が仮想マシンに伝わらなくなってしまった。

VM toolがインストールされたWindowsもDebianのインストーラーもキーボードやマウスが全く反応しなくなりました。
OSの起動はするし、「更新プログラム」のポップップもでるので、仮想マシン自体は普通に動いてます。
多分SSHとか設定してあればアクセスできるのかな?

VMware Fusion 8.5.19の動作不具合

不具合といってもすでにVMware Fusion 8.5.10はmacOS Mojaveなんて対応してないので仕方ないことですが
parallels mac Proは1台しか持っていなかったので、とりあえずMBAに余ってたライセンスでVMware Fusionを使っていましたが
なんだかんだ問題なく?(気づかないだけかも)WindowsもUbuntuも使えたのでそのまま使っていましたが
とうとうmacOS Mojave 10.14.2の更新でダメになりました。

Macのメジャーアップデートで起動しなくなるparallelsよりそこんところは好きだったんだけど
さすがにVMware Fusion 8.5.10は10.14.2まででした。
parallelsのProを追加するか、Fusion11にしてみるか。悩む

ERC721トークンを作成してOpenSeaに掲載してみる – Dapps

OpenSeaにトークンを掲載する方法

OpenSeaのチュートリアルをやってみる。

OpenSea Developer Tutorial
Simple tutorial for a customizable marketplace for buying and selling on OpenSea

SUGGEST EDITS
Want an instant, customizable marketplace for your game items, collectibles, or other ERC-721 assets? You’ve come to the right place.

This tutorial will show you how to go from start to finish building a storefront for your items. We’ll walk you through structuring your ERC721 contract and off-chain metadata, viewing your items on OpenSea, and testing out the auction flow for your items.

By the end of this tutorial, you’ll know how to integrate with OpenSea and create a custom storefront for your items, just like the OpenSea Creature example storefront in this tutorial.

引用 https://docs.opensea.io/docs/1-structuring-your-smart-contract

OpenSeaCreatures ERC721 contracts
About OpenSeaCreatures.
This is a very simple sample ERC721 for the purposes of demonstrating integration with the OpenSea marketplace. We include a script for minting the items.

Additionally, this contract whitelists the proxy accounts of OpenSea users so that they are automatically able to trade the ERC721 item on OpenSea (without having to pay gas for an additional approval). On OpenSea, each user has a “proxy” account that they control, and is ultimately called by the exchange contracts to trade their items. (Note that this addition does not mean that OpenSea itself has access to the items, simply that the users can list them more easily if they wish to do so)

引用 https://github.com/ProjectOpenSea/opensea-creatures


$ truffle deploy  --network rinkeby
Using network 'rinkeby'.

Running migration: 1_initial_migrations.js
  Deploying Migrations...
  ... 0xe301680767e2d01...hash
  Migrations: 0x629598f...hash
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying Creature...
  ... 0xf540...hash
  Creature: 0x40098d....コントラクトのアドレス
Saving artifacts...

GitHubのReadmeはこうなってるけど

Minting tokens.

After deploying to the Rinkeby network, there will be a contract on Rinkeby that will be viewable on Rinkeby Etherscan. For example, here is a recently deployed contract. You should set this contract address and the address of your Metamask account as environment variables when running the minting script:


export OWNER_ADDRESS=""
export CONTRACT_ADDRESS=""
export NETWORK="rinkeby"
node scripts/mint.js

HDWalletProviderを指定する際に、アドレスのインデックスを指定しようとmint.jsを編集してたら
GitHubのReadmeと指定するべき環境変数が違ったので注意。

OWNER_ADDRESSはmint.jsで読み込んでますが
CONTRACT_ADDRESSは読み込まれておらず
NFT(ERC721)とFACTORY(ガチャ)の分岐があるので
今回はNFT(ERC721)なので、FACTORY_CONTRACT_ADDRESSを指定します。


const HDWalletProvider = require("truffle-hdwallet-provider")
const web3 = require('web3')
const MNEMONIC = process.env.MNEMONIC
const INFURA_KEY = process.env.INFURA_KEY
const FACTORY_CONTRACT_ADDRESS = process.env.FACTORY_CONTRACT_ADDRESS
const NFT_CONTRACT_ADDRESS = process.env.NFT_CONTRACT_ADDRESS
const OWNER_ADDRESS = process.env.OWNER_ADDRESS

途中省略
async function main() {
    const provider = new HDWalletProvider(MNEMONIC, `https://${NETWORK}.infura.io/${INFURA_KEY}` , 5 )
    const web3Instance = new web3(
        provider
    )


    if (NFT_CONTRACT_ADDRESS) {
        const nftContract = new web3Instance.eth.Contract(NFT_ABI, NFT_CONTRACT_ADDRESS, { gasLimit: "1000000" })

        // Creatures issued directly to the owner.
        for (var i = 0; i < NUM_CREATURES; i++) {
            const result = await nftContract.methods.mintTo(OWNER_ADDRESS).send({ from: OWNER_ADDRESS });
            console.log("Minted creature. Transaction: " + result.transactionHash)
        }
    } else if (FACTORY_CONTRACT_ADDRESS) {

NETWORKはすでにデプロイ時に反映済みなので
NFT_CONTRACT_ADDRESS、OWNER_ADDRESSを指定して実行しました。


$ export NFT_CONTRACT_ADDRESS="0x4006....デプロイしたContractのアドレス"
$ export OWNER_ADDRESS="0x01234...オーナーとするアドレス"
$ node scripts/mint.js
Minted creature. Transaction: 0xc90108641fa6b7...TxHash
Minted creature. Transaction: 0x52a54629d83812...TxHash
Minted creature. Transaction: 0x876160fee54a33...TxHash
Minted creature. Transaction: 0x500a341ec082c0...TxHash
Minted creature. Transaction: 0xc02abbbe93f762...TxHash

残高はあるのにtruffle deployで「Error encountered, bailing」- HDWalletProvider


Using network 'rinkeby'.

Running migration: 1_initial_migrations.js
  Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
insufficient funds for gas * price + value

今回で言えばrinkebyの残高があるアドレスはMetamaskの5番目に生成したアドレスで
HDWalletProviderがそのアドレスを見ていなかったのが原因
HDWalletProviderに指定したいアドレスのindexを引き渡してあげる。


return new HDWalletProvider(
          MNEMONIC,
          "https://rinkeby.infura.io/" + INFURA_KEY
        , index );

opensea向けのDappsを作ろうと思ったらnpm installでエラー – gyp ERR! not ok

npm installで「gyp ERR! not ok」となってしまう。


gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/usr/local/Cellar/node/10.11.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/dp/src/Ethereum/opensea-creatures/node_modules/sha3
gyp ERR! node -v v10.11.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

package.jsonをみたらNodeのバージョンが高すぎるみたい。。


"engines": {
    "node": "8.11.x",
    "npm": "5.6.x"
  }

nodebrewを使ってるので、切り替えてOK


nodebrew install-binary v8.11.0
nodebrew use v8.11.0