AGP Upgrade Assistant で 7.2 移行時にCause: manifestData.`package` must not be null

初回は、自動認識でダイアログから進むことになると思うが、

手動でやるなら以下から。


[Tools]

  ↓

[AGP Upgrade Assistant]

このステップでコケる。

Move package from Android manifest to build files

Declaration of a project's namespace using the package attribute of the Android manifest is deprecated in favour of a namespace declaration in build files.

なんすかねこれ。

 

Gradle sync failed: Cause: manifestData.`package` must not be null

Issue Tracker にありました。

AGP namespace property and app id suffix and Safe Args plugin don't work together

Using the new namespace property in build.gradle instead of the package attribute in AndroidManifest.xml while also using a custom applicationIdSuffix breaks androidx.navigation.safeargs plugin.

👉 Gradle sync failed: Cause: manifestData.`package` must not be null - Issue Tracker
👉 AGP namespace property and app id suffix and Safe Args plugin don't work together [232107688] - Visible to Public - Issue Tracker hatena-bookmark

どうやら、namespace の新記述は、

androidx.navigation.safeargs と同時に使えないようです。

使っているか、コード内を探してみました。


[Edit]

  ↓

[Find]

  ↓

[Find in Files ...]

androidx.navigation.safeargs

...

どうやら、ツールの書き換え内容は以下の様子。

👉 AndroidManifest の package 属性による名前空間宣言が廃止される - BattleProgrammerShibata hatena-bookmark

2行だけなので直接書き換えて namespace 記述は以前の形に戻す。と。

暫定的な対応なので、以下のようにFix版リリース時に注意が必要です。

👉 java.lang.IncompatibleClassChangeError: The method 'java.lang.Class java.lang.Object.getClass()' was expected to be of type interface but instead was found to be of type virtual hatena-bookmark


This version (1.2.0-alpha08) of the Compose Compiler requires Kotlin version 1.6.20 but you appear to be using Kotlin version 1.6.21 which is not known to be compatible.

こんなの出ましたけどー。


> Run with --scan to get full insights.


> Task :app:compileDebugKotlin FAILED
e: This version (1.2.0-alpha08) of the Compose Compiler requires Kotlin version 1.6.20 but you appear to be using Kotlin version 1.6.21 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).

言われるがままに、kotlin のバージョンを、1.6.20 に下げればこのエラーは消えてビルド通りますが、

Kotlin 安定版の 1.6.21 を 1.6.20 を下げる

ってのどうなのと。

 

Compose コンパイラ と Kotlin の互換性


Compose Compiler	Compatible Kotlin
1.2.0-alpha08		1.6.20
1.2.0-alpha07		1.6.10
1.2.0-alpha06		1.6.10

以下から、英語版 (言語を「English」に切り替える) にすると分かりやすいです。

👉 Compose to Kotlin Compatibility Map  |  Android Developers hatena-bookmark

Kotlin stable 1.6.21 に対応する Compose Compiler は 今現在は pre-release 版しかありません。


 

何でこんなことになるのか?


通常、安定版とアルファ版の両方が同じ日に修正された状態でリリースされると思われます。しかし、AndroidXのモノレポとその関連インフラは、実はこれを阻んでいます。リリースブランチが一つしかないので、Accompanist のような通常のプロジェクトとは異なり、別々に行うことを余儀なくされるのです。


Kotlin 1.6.20のアーティファクトがリリースされてから1週間。ComposeをアップデートするCLはリリース前にできていた。しかし、AndroidXのモノレポでは、無関係な50のライブラリを同時にアップデートすることを強制されるため、未だに不完全です。健全なプロジェクトであれば、同じ日にリリースするはずです。

Drop "androidx" from Jetpack Compose package name, for multiplatform, before 1​.​0 release.
👉 キャンペーン · Drop "androidx" from Jetpack Compose package name, for multiplatform, before 1​.​0 release. · Change.org hatena-bookmark

Compose コンパイラを開発する環境にいろいろ問題とかあるんですかね。

👉 公式 android デベロッパー の英語ページに日本語ページが遅れてる件 hatena-bookmark

 

2022-05-21 追記

1.6.21 対応の beta版がリリースされています。

compose の父が!


これも「English」ページのみ確認できます。注意です!
kotlinCompilerExtensionVersion = "1.2.0-beta02"

👉 Compose to Kotlin Compatibility Map  |  Android Developers hatena-bookmark



Gradle タスクリストが見えない件【Android Studio】

見えなくなりましたね、

これ Task のリスト。

gradle task list

その理由。

Gradle task list is large and slow to populate in Android projects. This feature by default is disabled for performance reasons. You can re-enable it in: Settings | Experimental | Do not build Gradle task list during Gradle sync.

Androidプロジェクトでは、Gradleのタスクリストが大きく、作成に時間がかかります。パフォーマンス上の理由から、この機能はデフォルトで無効になっています。以下で再有効化することができます。


Preferences

↓

Experimental

↓

Do not build Gradle task list during Gradle sync.

Do not build Gradle task list during Gradle sync

👉 Missing [app | android | Tasks | androidDependencies] in the gradel panel [185420705] - Visible to Public - Issue Tracker hatena-bookmark
👉 Gradle tasks are not showing in the gradle tool window in Android Studio 4.2 - Stack Overflow hatena-bookmark

使わないほうがいいんでしょうね。

将来的になくなる機能なのでしょう。

 

タスク一覧表示する

コマンドランチャー的なものが表示されるようになってるのですが、困るのは、オプション部分をはっきり覚えてないので入力ができないことです。

「tasks」 と入力するのが良さげです。

gradle tasks

クリックして選択はできませんが、タスクオプションの一覧は表示されるので、それを見たりコピーして入力できるようになります。


Android tasks
-------------
androidDependencies - Displays the Android dependencies of the project.
signingReport - Displays the signing info for the base and test modules
sourceSets - Prints out all the source sets defined in this project.

Build tasks
-----------
assemble - Assemble main outputs for all the variants.
assembleAndroidTest - Assembles all the Test applications.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildKotlinToolingMetadata - Build metadata json file containing information about the used Kotlin tooling
buildNeeded - Assembles and tests this project and all projects it depends on.
bundle - Assemble bundles for all the variants.
clean - Deletes the build directory.
compileDebugAndroidTestSources
compileDebugSources
compileDebugUnitTestSources
compileReleaseSources
compileReleaseUnitTestSources

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Firebase Crashlytics tasks
--------------------------
injectCrashlyticsMappingFileIdDebug - Injects a mapping file id into the app, used by Crashlytics for deobfuscation.
injectCrashlyticsMappingFileIdRelease - Injects a mapping file id into the app, used by Crashlytics for deobfuscation.
uploadCrashlyticsMappingFileDebug - Uploads mapping files to Crashlytics for crash deobfuscation.
uploadCrashlyticsMappingFileRelease - Uploads mapping files to Crashlytics for crash deobfuscation.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'Sample'.
dependencies - Displays all dependencies declared in root project 'Sample'.
dependencyInsight - Displays the insight into a specific dependency in root project 'Sample'.
help - Displays a help message.
javaToolchains - Displays the detected java toolchains.
outgoingVariants - Displays the outgoing variants of root project 'Sample'.
projects - Displays the sub-projects of root project 'Sample'.
properties - Displays the properties of root project 'Sample'.
tasks - Displays the tasks runnable from root project 'Sample' (some of the displayed tasks may belong to subprojects).

Install tasks
-------------
installDebug - Installs the Debug build.
installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build.
uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
uninstallRelease - Uninstalls the Release build.

Verification tasks
------------------
check - Runs all checks.
checkJetifier - Checks whether Jetifier is needed for the current project
connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedCheck - Runs all device checks on currently connected devices.
connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.
deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
deviceCheck - Runs all device checks using Device Providers and Test Servers.
lint - Runs lint on the default variant.
lintAnalyzeDebug - Run lint analysis on the debug variant
lintAnalyzeRelease - Run lint analysis on the release variant
lintDebug - Print text output from the corresponding lint report task
lintFix - Runs lint on the default variant and applies any safe suggestions to the source code.
lintFixDebug - Fix lint on the debug variant
lintFixRelease - Fix lint on the release variant
lintRelease - Print text output from the corresponding lint report task
lintReportDebug - Run lint on the debug variant
lintReportRelease - Run lint on the release variant
test - Run unit tests for all variants.
testDebugUnitTest - Run unit tests for the debug build.
testReleaseUnitTest - Run unit tests for the release build.


【Android Studio】プラグイン「Proguard Retrace Unscrambler」で難読化されたスタックトレースを解除してみた

あってもいいよな、ありそうだ、と思っていたこのプラグイン。

Proguard Retrace Unscrambler

Adds Unscrambler support for Proguard's mapping files and Android's R8 mapping files. Use to de-obfuscate your stacktrace

Proguard Retrace Unscrambler

Proguard Retrace Unscrambler

👉 Proguard Retrace Unscrambler - IntelliJ IDEA & Android Studio Plugin | Marketplace 
👉 chrimaeon/proguard-retrace-unscrambler: An Intellij IDEA and Android Studio Plugin to de-obfuscate your Proguard stack traces 

使い方。

1. 難読化されたスタックトレースをコピーする。
2. メニューから [Analyze] - [Stack Trace or Thread Dump ...]
3. 「Unscramble stacktrace」をチェックして有効化する。
4. 「Proguard Retrace」を選択する。
5. Proguard/R8 の mapping.txt を「Log file」に選択する。
6. 難読化されているスタックトレースを貼り付ける。
7. 「OK」を押すと難読化が解除されて下部 Run ウインドウに表示される。

Proguard Retrace Unscrambler

なんとなく読めるようになりましたが、「null」と失敗しているところも見当たります。

Proguard Retrace Unscrambler

惜しいです。

公式に案内されている方法では完全に読めます。



java -jar ~/Library/Android/sdk/tools/proguard/lib/proguardgui.jar

java -jar ~/Library/Android/sdk/tools/proguard/lib/proguardgui.jar

しかし、このプラグインてサードパーティでなく、公式の同梱で作れないものなのかな ?

👉 R8 で 難読化 された スタックトレース を元に戻す 


GitHub Gist に置いた Javascript をブックマークレットとして実行する

普通に、document で読み込んだら使えませんし。

"Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec."

ちょっとしたコードをシェアするのにGistは便利ですが、HTMLとしてそのままブラウザに表示したり、JSONとして利用するには少々難があります。レスポンスヘッダのContent-Typeがtext/plain固定なので、Rawデータにアクセスしてもソース表示に。

👉 GistのHTMLを直接表示する方法 - Qiita 

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.

禁断の eval() 使います。

👉 eval() - JavaScript | MDN 


(
  () => {
    fetch('https://gist.githubusercontent.com/path/to/raw/script.js')
      .then(response => response.text())
      .then(script => eval(script))
  }
)();

通信部分は Future な Promise でシンプルに書くことができます。

👉 Fetch の使用 - Web API | MDN 

思ってたより良い進化をしてる javascript に驚きました。

まずは、一つの Gist を書き換えながら、ブックマークをポチポチしながら作りますか。

おまけ

ついでに、Gist の URL をまとめておきます。


[top]
https://{main_host}/{user_id}/{gist_id}

[edit] *
https://{main_host}/{user_id}/{gist_id}/edit

[raw latest] *
https://{raw_host}/{user_id}/{gist_id}/raw/[{file_name}]

[raw permanent]
https://{raw_host}/{user_id}/{gist_id}/raw/{revision_id}/[{file_name}]

そのうちまた変わるのでしょうがね。

👉 iPhone Android アプリ横断検索 
👉 Google「Closure Compiler」 (クロージャコンパイラ) の使い方