pretty

Sunday 23 June 2024

Kotlin Multiplatform Wizard: problems building the project in the Xcode 15.4

The sample iOS project from Kotlin Multiplatform Wizard may fail to be built in XCode 15.4. The following steps should help to resolve these.

1. Add task("testClasses") to KotlinProject/shared/build.gradle.kts, inside the kotlin block:

kotlin {
    task("testClasses")
...
}


2. If XCode cannot build the project due to pointing to Java 11, showing an error: Android Gradle plugin requires Java 17 to run. You are currently using Java 11 - put the path to Java 17 to KotlinProject/gradle.properties:

org.gradle.java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home

This path depends on Android Studio ans OS version. The above is the path used in Android Studio Jellyfish on MacOS.

Sunday 2 July 2023

Running Docker MySQL container on MacOS

1. Launch docker desktop server on MacOS via Launchpad icon.

Docker desktop application can be downloaded from the docker web site.
After launch the docker icon should appear on the right top icon tray of the menu. Docker can be used from command line now, lets check the docker is running and the version.

docker --version
Docker version 23.0.5, build bc4487a

1.1 Get docker mysql image.
docker run mysql:latest

2. Launch MySQL docker container.
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pwd -d mysql
Arguments:
-p publish port from container and map it to host OS port, this is to connect to MySQL from the outside environment later.
-e env variables, used only MYSQL_ROOT_PASSWORD in this case and set a new 'pwd' for the root user. Optionally, we can create more users with corresponding passwords on this step, providing more env parameters like this:
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pwd MYSQL_USER=newuser MYSQL_PASSWORD newpwd -d mysql
-d daemon mode
-'mysql' would be a new container name

2.1 Check that container is running and get its id from table CONTAINER ID.
docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
7fc7ee05859d   mysql     "docker-entrypoint.s…"   26 minutes ago   Up 26 minutes   0.0.0.0:3306->3306/tcp, 33060/tcp   angry_fermi

3. Connect to mysql container by CONTAINER ID (get it from previous step) using docker shell.
docker exec -it 7fc7ee05859d bash
Arguments:
-it interactive mode (shell)
-'7fc7ee05859d' is a container id
Now, inside the container, we can launch mysql console providing the root user name and actual password that was set on step 2.
mysql -uroot -p       
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 8.0.33 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

3.1 Lets check that MySQL is really available to the outside of the container, as we mapped internal port of the container to OS port 3306 on step 2.

One of the options to do this is to install MySQL workbench application from Oracle on the host computer. When launched it allows to create a new MySQL Connection. Supplying 127.0.0.1:3306 for this new connection (that is localhost:port, that we mapped to on step 2), we should be able to connect to the DB inside the docker container.

Saturday 15 April 2023

Inspect sqlite database file from iOS emulator

1. View sqlite file location.

Launch XCode and follow these steps:
- XCode Menu Bar > Product > Scheme > Edit Scheme
- Run option
- Add or modify the Arguments passed on launch to contain -com.apple.CoreData.SQLDebug 1
- Launch the application and wait for Output to have a string with db location, like:

CoreData: annotation: Connecting to sqlite database file at "/Users/user/Library/Developer/CoreSimulator/Devices/DA54BPCB-39F1-4D19-888A-FA146477606DD/data/Containers/Data/Application/567443-7273-4B75-BFDA-86756/Library/Application Support/Data.sqlite"

2. Knowing the location, open Terminal and cd into SQlite db location. It may look like this:

cd "/Users/user/Library/Developer/CoreSimulator/Devices/DA54BPCB-39F1-4D19-888A-FA146477606DD/data/Containers/Data/Application/567443-7273-4B75-BFDA-86756/Library/Application Support/"

Copy 3 database files from this directory to desktop, or some other convenient directory:
cp Data.sqlite /Users/user/Desktop
cp Data.sqlite-shm /Users/user/Desktop
cp Data.sqlite-wal /Users/user/Desktop

3. Open the copied Data.sqlite from /Desktop with apps from AppStore, like Ridill SQLite or SQLiteFlow.