<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Karlmax Berlin - Medium]]></title>
        <description><![CDATA[We design and develop software for Android, iOS and mobile web applications. - Medium]]></description>
        <link>https://medium.com/karlmax-berlin?source=rss----c35956f199fa---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Karlmax Berlin - Medium</title>
            <link>https://medium.com/karlmax-berlin?source=rss----c35956f199fa---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 16:53:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/karlmax-berlin" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to install Kubernetes on Raspberry PI]]></title>
            <link>https://medium.com/karlmax-berlin/how-to-install-kubernetes-on-raspberry-pi-53b4ce300b58?source=rss----c35956f199fa---4</link>
            <guid isPermaLink="false">https://medium.com/p/53b4ce300b58</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[Ralph Bergmann]]></dc:creator>
            <pubDate>Fri, 09 Sep 2022 13:11:42 GMT</pubDate>
            <atom:updated>2023-04-26T08:30:07.847Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial (it is more of a step-by-step guide than an article), I will show you how you can install Kubernetes on a Raspberry PI 4 cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QJ-IPcJvGv0SmuMGIgU3vw.png" /></figure><h3>Install Raspberry PI OS on each Raspberry</h3><p>First of all, you need to install the OS on each Raspberry. Use the <a href="https://www.raspberrypi.com/software/">Raspberry Pi Imager</a> to write the image on an SD Card.</p><figure><img alt="Raspberry Pi Imager" src="https://cdn-images-1.medium.com/max/680/1*PikUtTmz_usW5bVF_hrLSA.png" /></figure><p>Click the CHOOSE OS button and select Raspberry PI OS Lite (64-bit) from the Raspberry PI OS (other) section.</p><figure><img alt="select Raspberry PI OS Lite (64-bit)" src="https://cdn-images-1.medium.com/max/680/1*UUA-wIaZuN034T8A7ePMOQ.png" /></figure><p>In the Advanced options (the gear icon/button) set the hostname and your username, enable SSH and click SAVE.</p><figure><img alt="settings menu" src="https://cdn-images-1.medium.com/max/680/1*2Pu098NONJQ5xbkOVP9dLg.png" /></figure><p>Now insert the SD Card into a card reader, choose it and write the image.</p><p>Repeat these steps for all SD Cards, but <strong>choose a different hostname</strong> for each one. When you are done with all SD Cards, insert them into the Raspberry PIs and boot them.</p><blockquote><strong>You must perform the following steps on all Raspberry PIs you want to add to your cluster.</strong></blockquote><blockquote>I wrote an <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html">Ansible Playbook</a> for the following steps. Scroll down to see how to run it and save some time.</blockquote><h3>Update the OS</h3><p>Before we install Kubernetes, we need to update the OS. To do so, login into each Raspberry via SSH and run the following command:</p><pre>$ sudo apt update -y &amp;&amp; sudo apt dist-upgrade -y</pre><p>Sometimes you get a new Kernel, so rebooting the Raspberry is a good idea.</p><pre>$ sudo reboot</pre><h3>Add cgroup flags</h3><p>Add cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 to the end of the /boot/cmdline.txt file. <em>The content of this file is one line without any line breaks.</em></p><pre>$ echo &quot; cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1&quot; | sudo tee -a  /boot/cmdline.txt</pre><h3>Disable and uninstall swap</h3><p>Run the following commands to disable and uninstall the swap file:</p><pre>$ sudo dphys-swapfile swapoff<br>$ sudo dphys-swapfile uninstall<br>$ sudo apt purge -y dphys-swapfile<br>$ sudo apt autoremove -y</pre><p>You can test that swap has been disabled with free -m.</p><figure><img alt="swap disabled" src="https://cdn-images-1.medium.com/max/1015/1*DGTbDFliPLBQ6cVDzmrTxQ.png" /></figure><h3>Install and set up the Container Runtime</h3><blockquote>See also <a href="https://kubernetes.io/docs/setup/production-environment/container-runtimes/">Container Runtimes in the Kubernetes Documentation</a></blockquote><h4>Install containerd</h4><pre>$ sudo apt install -y containerd containernetworking-plugins</pre><h4>Set up containerd with cgroup</h4><blockquote>See also <a href="https://github.com/containerd/containerd/issues/4203#issuecomment-651532765">https://github.com/containerd/containerd/issues/4203#issuecomment-651532765</a></blockquote><p>Replace the content of /etc/containerd/config.toml:</p><pre>$ cat &lt;&lt;EOF | sudo tee /etc/containerd/config.toml<br>version = 2<br>[plugins]<br>  [plugins.&quot;io.containerd.grpc.v1.cri&quot;]<br>    [plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd]<br>      [plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd.runtimes]<br>        [plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd.runtimes.runc]<br>          runtime_type = &quot;io.containerd.runc.v2&quot;<br>          [plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd.runtimes.runc.options]<br>            SystemdCgroup = true<br>EOF</pre><figure><img alt="/etc/containerd/config.toml" src="https://cdn-images-1.medium.com/max/1015/1*Od5pRaTY0F39DDfdJRr3_w.png" /></figure><h3>Forwarding IPv4 and letting iptables see bridged traffic</h3><blockquote>See also <a href="https://kubernetes.io/docs/setup/production-environment/container-runtimes/#forwarding-ipv4-and-letting-iptables-see-bridged-traffic">Forwarding IPv4 and letting iptables see bridged traffic</a></blockquote><pre>$ cat &lt;&lt;EOF | sudo tee /etc/modules-load.d/k8s.conf<br>overlay<br>br_netfilter<br>EOF<br> <br>$ sudo modprobe overlay<br>$ sudo modprobe br_netfilter<br> <br>$ cat &lt;&lt;EOF | sudo tee /etc/sysctl.d/k8s.conf<br>net.bridge.bridge-nf-call-iptables  = 1<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.ipv4.ip_forward                 = 1<br>EOF<br>$ sudo sysctl --system</pre><h3>Install kubeadm</h3><blockquote>See also <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/">Installing kubeadm</a></blockquote><pre>$ sudo apt update<br>$ sudo apt install -y apt-transport-https ca-certificates curl<br><br>// Download the Google Cloud public signing key:<br>$ sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg<br><br>// Add the Kubernetes apt repository:<br>$ echo &quot;deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main&quot; | sudo tee /etc/apt/sources.list.d/kubernetes.list<br><br>// Update `apt` package index, install kubelet, kubeadm and kubectl, and pin their version:<br>$ sudo apt update<br>$ sudo apt install -y kubelet kubeadm kubectl<br>$ sudo apt-mark hold kubelet kubeadm kubectl</pre><h3>Install Cluster Networking</h3><blockquote><a href="https://github.com/flannel-io/flannel">Flannel</a> is a simple and easy way to configure a layer 3 network fabric designed for Kubernetes. (<a href="https://github.com/flannel-io/flannel#flannel">Flannel</a>)</blockquote><pre>$ wget https://github.com/flannel-io/flannel/releases/download/v0.19.2/flanneld-arm64<br>$ sudo chmod +x flanneld-arm64<br>$ sudo cp flanneld-arm64 /usr/local/bin/flanneld<br>$ sudo mkdir -p /var/lib/k8s/flannel/networks</pre><p>In a later step, we will add Flannel to the cluster.</p><h3>Ansible for lazy people</h3><blockquote><a href="https://www.ansible.com/">Ansible</a> is an IT automation tool. It can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates. (<a href="https://docs.ansible.com/ansible/latest/index.html#about-ansible">Ansible Documentation</a>)</blockquote><p>I wrote an <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#intro-to-playbooks">Ansible Playbook</a> to automate all the steps above. To run the playbook, you first need to <a href="https://docs.ansible.com/ansible/latest/installation_guide/index.html">install Ansible</a>. On macOS, you can install it with <a href="https://formulae.brew.sh/formula/ansible">brew install ansible</a> (what I did). You also need an <a href="https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#how-to-build-your-inventory">inventory</a>. Mine looks like this:</p><pre>[raspis]<br>10.0.0.[11:14]<br><br>[raspis:vars]<br>ansible_user=ralph<br><br>[k8s_main]<br>10.0.0.11<br><br>[k8s_worker]<br>10.0.0.[12:14]</pre><p>The playbook uses the IP addresses from the raspis group to run all the tasks on these hosts.</p><pre>---<br>- name: Playbook to install the necessary things to run k8s on Raspberry PIs<br>  hosts: raspis<br>  become: yes<br>  gather_facts: no<br>  tasks:<br>    - name: Update repositories cache and upgrade system<br>      ansible.builtin.apt:<br>        update_cache: yes<br>        upgrade: dist<br>        cache_valid_time: 3600<br>        autoclean: yes<br>        autoremove: yes<br><br>    - name: Check if a reboot is needed<br>      register: reboot_required_file<br>      stat:<br>        path: /var/run/reboot-required<br>        get_md5: no<br><br>    - name: Reboot if needed<br>      ansible.builtin.reboot:<br>        msg: &quot;Reboot initiated by Ansible for kernel updates&quot;<br>        connect_timeout: 5<br>        reboot_timeout: 300<br>        pre_reboot_delay: 0<br>        post_reboot_delay: 30<br>        test_command: uptime<br>      when: reboot_required_file.stat.exists<br><br>    - name: Install vim and aptitude<br>      ansible.builtin.apt:<br>        pkg:<br>          - vim<br>          - aptitude<br><br>    - name: Create Aptitude config directory<br>      ansible.builtin.file:<br>        path: /root/.aptitude/<br>        state: directory<br>        recurse: yes<br>        owner: root<br>        group: root<br>        mode: &#39;0700&#39;<br><br>    - name: Configure Aptitude<br>      ansible.builtin.copy:<br>        content: |<br>          aptitude &quot;&quot;;<br>          aptitude::Keep-Unused-Pattern &quot;&quot;;<br>          aptitude::Delete-Unused-Pattern &quot;&quot;;<br>          aptitude::UI &quot;&quot;;<br>          aptitude::UI::Prompt-On-Exit &quot;false&quot;;<br>          aptitude::UI::Default-Grouping &quot;task,status&quot;;<br>          aptitude::AutoClean-After-Update &quot;true&quot;;<br>          aptitude::Clean-After-Install &quot;true&quot;;<br>          aptitude::Forget-New-On-Update &quot;true&quot;;<br>        dest: /root/.aptitude/config<br>        backup: yes<br>        owner: root<br>        group: root<br>        mode: &#39;0644&#39;<br><br>    - name: Modify ls alias<br>      ansible.builtin.lineinfile:<br>        path: /home/ralph/.bashrc<br>        backup: yes<br>        regexp: &#39;^    alias ls=&#39;&#39;ls --color=auto&#39;&#39;$&#39;<br>        line: &#39;    alias ls=&#39;&#39;ls --color=auto -lahpG&#39;&#39;&#39;<br><br><br>    # disable swap<br><br>    - name: Check whether a package called dphys-swapfile is installed<br>      ansible.builtin.package_facts:<br>        manager: auto<br><br>    - name: Turn off &quot;dphys-swapfile&quot;<br>      ansible.builtin.command: dphys-swapfile swapoff<br>      when: &quot;&#39;dphys-swapfile&#39; in ansible_facts.packages&quot;<br><br>    - name: Uninstall &quot;dphys-swapfile&quot;<br>      ansible.builtin.command: dphys-swapfile uninstall<br>      when: &quot;&#39;dphys-swapfile&#39; in ansible_facts.packages&quot;<br><br>    - name: Remove and purge &quot;dphys-swapfile&quot; package<br>      ansible.builtin.apt:<br>        pkg: dphys-swapfile<br>        state: absent<br>        purge: yes<br>        autoclean: yes<br>        autoremove: yes<br>      when: &quot;&#39;dphys-swapfile&#39; in ansible_facts.packages&quot;<br><br><br>    # Configure cgroup<br><br>    - name: Enable cgroup in /boot/cmdline.txt<br>      ansible.builtin.lineinfile:<br>        path: /boot/cmdline.txt<br>        backrefs: yes<br>        regexp: &#39;^console(.*) rootwait$&#39;<br>        line: &#39;\g&lt;0&gt; cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1&#39;<br><br><br>    # Install and configure Container Runtime<br><br>    - name: Install Container Runtime<br>      ansible.builtin.apt:<br>        pkg:<br>          - containerd<br>          - containernetworking-plugins<br><br>    - name: Configure containerd<br>      ansible.builtin.copy:<br>        content: |<br>          version = 2<br>          [plugins]<br>            [plugins.&quot;io.containerd.grpc.v1.cri&quot;]<br>              [plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd]<br>                [plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd.runtimes]<br>                  [plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd.runtimes.runc]<br>                    runtime_type = &quot;io.containerd.runc.v2&quot;<br>                    [plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd.runtimes.runc.options]<br>                      SystemdCgroup = true<br>        dest: /etc/containerd/config.toml<br>        backup: yes<br>        owner: root<br>        group: root<br>        mode: &#39;0644&#39;<br><br><br>    # Forwarding IPv4 and letting iptables see bridged traffic<br><br>    - name: create /etc/modules-load.d/k8s.conf<br>      ansible.builtin.copy:<br>        content: |<br>          overlay<br>          br_netfilter<br>        dest: /etc/modules-load.d/k8s.conf<br>        backup: yes<br>        owner: root<br>        group: root<br>        mode: &#39;0644&#39;<br><br>    - name: modprobe overlay<br>      ansible.builtin.command: modprobe overlay<br><br>    - name: modprobe br_netfilter<br>      ansible.builtin.command: modprobe br_netfilter<br><br>    - name: Create /etc/sysctl.d/k8s.conf<br>      ansible.builtin.copy:<br>        content: |<br>          net.bridge.bridge-nf-call-iptables  = 1<br>          net.bridge.bridge-nf-call-ip6tables = 1<br>          net.ipv4.ip_forward                 = 1<br>        dest: /etc/sysctl.d/k8s.conf<br>        backup: yes<br>        owner: root<br>        group: root<br>        mode: &#39;0644&#39;<br><br>    - name: sysctl --system<br>      ansible.builtin.command: sysctl --system<br><br><br>    # Install kubeadm<br><br>    - name: Install apt-transport-https ca-certificates<br>      ansible.builtin.apt:<br>        pkg:<br>          - apt-transport-https<br>          - ca-certificates<br>          - curl<br><br>    - name: Download the Google Cloud public signing key<br>      ansible.builtin.get_url:<br>        url: https://packages.cloud.google.com/apt/doc/apt-key.gpg<br>        dest: /usr/share/keyrings/kubernetes-archive-keyring.gpg<br>        owner: root<br>        group: root<br>        mode: &#39;0644&#39;<br><br>    - name: Add the Kubernetes apt repository<br>      ansible.builtin.apt_repository:<br>        repo: &quot;deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main&quot;<br>        state: present<br>        filename: kubernetes<br>        update_cache: yes<br><br>    - name: Install kubelet kubeadm kubectl<br>      ansible.builtin.apt:<br>        pkg:<br>          - kubelet<br>          - kubeadm<br>          - kubectl<br><br>    - name: Hold kubelet<br>      dpkg_selections:<br>        name: kubelet<br>        selection: hold<br><br>    - name: Hold kubeadm<br>      dpkg_selections:<br>        name: kubeadm<br>        selection: hold<br><br>    - name: Hold kubectl<br>      dpkg_selections:<br>        name: kubectl<br>        selection: hold<br><br><br>    # Download and install Flannel<br><br>    - name: Download and install Flannel<br>      ansible.builtin.get_url:<br>        url: https://github.com/flannel-io/flannel/releases/download/v0.19.2/flanneld-arm64<br>        dest: /usr/local/bin/flanneld<br>        owner: root<br>        group: root<br>        mode: &#39;0755&#39;<br><br>    - name: Create Flannel networks directory<br>      ansible.builtin.file:<br>        path: /var/lib/k8s/flannel/networks<br>        state: directory<br>        recurse: yes<br>        owner: root<br>        group: root<br>        mode: &#39;0755&#39;<br><br><br>    # reboot<br><br>    - name: reboot<br>      reboot:</pre><p>You can then run the playbook:</p><pre>$ ansible-playbook &lt;filename&gt;.yaml</pre><blockquote><strong>Perform the following steps only on the main host in your cluster.</strong></blockquote><h3>Initialize the Kubernetes cluster</h3><pre>$ sudo kubeadm init --pod-network-cidr=10.244.0.0/16</pre><p>I found nothing about the pod-network-cidr parameter and what IP address it needs to be…. but it works so far.</p><figure><img alt="kubeadm init" src="https://cdn-images-1.medium.com/max/1024/1*T_1JNOmp0LmKJRRPZaEdUg.png" /></figure><p>In the log, you will see a kubeadm join command. Save it in a secure space. You need it later to let the hosts join your cluster. But everyone with this command and internet access to your cluster can also join the cluster with this command.</p><p>Copy the Kubernetes config into your home directory:</p><pre>$ mkdir -p $HOME/.kube<br>$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config<br>$ sudo chown $(id -u):$(id -g) $HOME/.kube/config</pre><h3>Add Flannel to the cluster</h3><pre>$ kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml</pre><h3>Install MetalLB (External LoadBalancer)</h3><blockquote><a href="https://metallb.universe.tf/">MetalLB</a> hooks into your Kubernetes cluster, and provides a network load-balancer implementation. In short, it allows you to create Kubernetes services of type LoadBalancer in clusters that don’t run on a cloud provider, and thus cannot simply hook into paid products to provide load balancers. (<a href="https://metallb.universe.tf/concepts/">MetalLB</a>)</blockquote><p>In short: you need it to access the pods in your cluster from outside.</p><h4>Add MetalLB to the cluster</h4><pre>$ kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml<br>$ kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml</pre><h4>Configure MetalLB</h4><pre>$ cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  namespace: metallb-system<br>  name: config<br>data:<br>  config: |<br>    address-pools:<br>    - name: default<br>      protocol: layer2<br>      addresses:<br>      - 10.0.0.200-10.0.0.250<br>---<br>EOF</pre><p>The addresses must be from the range of your local network. You must also reserve these IP addresses so that your DHCP server can’t assign them to other clients in your network.</p><h3>Mostly done: add the hosts to the cluster</h3><p>Now it’s time to add the hosts to the cluster. On each host run the kubeadm join command you got earlier.</p><figure><img alt="add hosts to the cluster" src="https://cdn-images-1.medium.com/max/1024/1*efQP1HIbQ9yOVfbzsnOiDA.png" /></figure><p>kubectl get nodes -o wide shows all hosts in your cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NeVZVH20lcnPAAsZ1vKzYg.png" /></figure><p>You are now done. The cluster is set up, and you can start using it.</p><h3>A simple test</h3><p>Install a small and straightforward pod to test the cluster. The pod does nothing more than respond immediately with ping? pong!</p><pre>$ cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: ping<br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: ping<br>  namespace: ping<br>  labels:<br>    app: ping<br>spec:<br>  selector:<br>    matchLabels:<br>      app: ping<br>  replicas: 2<br>  template:<br>    metadata:<br>      labels:<br>        app: ping<br>    spec:<br>      containers:<br>        - name: ping<br>          image: dasralph/ping:arm64_0.0.5<br>          ports:<br>            - containerPort: 8080<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: ping<br>  namespace: ping<br>  labels:<br>    app: ping<br>spec:<br>  type: LoadBalancer<br>  selector:<br>    app: ping<br>  ports:<br>    - port: 80<br>      targetPort: 8080<br>      protocol: TCP<br>---<br>EOF</pre><p>The script installs the pod two times and creates a service for that. Your cluster should now look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DEYvXpHuHElvawbc70d1pw.png" /></figure><p>The ping service got an EXTERNAL IP, in this case 10.0.0.200. You can invoke the ping service with curl 10.0.0.200/ping -v. It will also return the IP address of the pod that responded to your request. You will get different IP addresses if you call the curl command repeatedly. This means that not always the same pod responds to your request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rYWIlstlAZWoM_3lA3aw2g.png" /></figure><p>If you want, you can delete the whole ping service with all of its pods with:</p><pre>$ kubectl delete namespace ping</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53b4ce300b58" width="1" height="1" alt=""><hr><p><a href="https://medium.com/karlmax-berlin/how-to-install-kubernetes-on-raspberry-pi-53b4ce300b58">How to install Kubernetes on Raspberry PI</a> was originally published in <a href="https://medium.com/karlmax-berlin">Karlmax Berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Move your layout up to a certain View when Keyboard is showing [Android]]]></title>
            <link>https://medium.com/karlmax-berlin/move-your-layout-up-to-a-certain-view-when-keyboard-is-showing-android-6207d99049ba?source=rss----c35956f199fa---4</link>
            <guid isPermaLink="false">https://medium.com/p/6207d99049ba</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[keyboard]]></category>
            <dc:creator><![CDATA[Claus Chierici]]></dc:creator>
            <pubDate>Thu, 10 Jun 2021 16:50:23 GMT</pubDate>
            <atom:updated>2022-06-14T19:37:10.949Z</atom:updated>
            <content:encoded><![CDATA[<p>When the keyboard opens up it consumes its space on the screen and overlaps the UI of your app.</p><p>To avoid that the corresponding input field is also overlapped you can simply add</p><pre>&lt;activity<br>    ...<br>    android:windowSoftInputMode=”adjustResize” /&gt;</pre><p>to the Manifest.xml. So the apps UI always moves up to the input field that just got the focus.</p><p>So far so good, but what if you need to have some more of your screen to be visible while the keyboard is opened? E.g. you have a text field below your input field that gives some important information or feedback on that data to be typed in the input field.</p><p>Well, one solution to achieve this is to put everything inside a ScrollView and just scroll up to the required position when the keyboard appears.</p><h4>1. Detect keyboard is open</h4><p>A good place to check if a keyboard is open or not is the</p><pre>ViewTreeObserver.OnGlobalLayoutListener</pre><p>resp. its callback</p><pre>onGlobalLayout()</pre><p>which is always called when the layout state of your current view tree has changed or any visibility changes happened.</p><p>You need to register your <strong>OnGlobalLayoutListener </strong>in <strong>onResume()</strong> and unregister in <strong>onPause()</strong>.</p><p>On how to check if the keyboard has opened please refer to the following article. You’ll find code snippets for some extension functions there:</p><p><a href="https://proandroiddev.com/how-to-detect-if-the-android-keyboard-is-open-269b255a90f5">How to detect if the android keyboard is open</a></p><p>(Thanks to the author).</p><h4>2. Scroll to the wanted position</h4><p>After applying the code snippets from the article above you can implement your <strong>OnGlobalLayoutListener</strong> as follows (given that you do this in a Fragment):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3bb603c4b6f3d186368620570ad7f40/href">https://medium.com/media/c3bb603c4b6f3d186368620570ad7f40/href</a></iframe><p>Note that <strong>MyScrollView </strong>and<strong> MyVisibleView </strong>should be<strong> </strong>the references to your views. Yes, the ones you retrieved by <strong>findViewByID()</strong> in the distant past. <br>If you use view binding in the meantime this could look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06e4781a7ef40a18479d22a12a7d65df/href">https://medium.com/media/06e4781a7ef40a18479d22a12a7d65df/href</a></iframe><p>To round this up you can add a bottom padding to the ScrollView of your layout so there is a bit space between the keyboard and <strong>MyVisibleView.<br></strong>Note that adding the padding to the view itself will have no effect here.<br>If you want to have a 200ms delay, or more, or less is entirely up to your taste.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6207d99049ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/karlmax-berlin/move-your-layout-up-to-a-certain-view-when-keyboard-is-showing-android-6207d99049ba">Move your layout up to a certain View when Keyboard is showing [Android]</a> was originally published in <a href="https://medium.com/karlmax-berlin">Karlmax Berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Localizing Android in-app strings without using Phrase]]></title>
            <link>https://medium.com/karlmax-berlin/android-workaday-life-1-adding-lots-of-localized-in-app-strings-1a6510ad45c2?source=rss----c35956f199fa---4</link>
            <guid isPermaLink="false">https://medium.com/p/1a6510ad45c2</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Claus Chierici]]></dc:creator>
            <pubDate>Mon, 12 Apr 2021 08:40:43 GMT</pubDate>
            <atom:updated>2021-04-07T14:39:50.449Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro</h3><p>This is my first story on Medium. I am a Senior Android Developer and want to share some bits of my daily experience by writing short stories the way i’d like to read them by myself.</p><h3>On the topic</h3><p>These days my PO wants me to create a list of 374 built-in strings of an app to hand it over to a translation service which would translate all strings to 7 new languages. And of course after getting the translation results i would be the one with the task to apply the strings into the app. And no, Phrase or similar services was not an option.</p><h3>How i resolved it</h3><p>I choose Excel to have at least the opportunity to have everything in separate columns: The string identifiers next to the localized strings. <br>Copying the identifiers and the default language into the Excel sheet was easy:</p><ul><li>Open the strings.xml in the Translations Editor of Android Studio</li><li>Select the columns of the identifiers and the default language and just copy and paste it to columns in the Excel sheet</li></ul><p>My idea was to do it just the other way round when the translations would be ready.</p><ul><li>Of course i made sure not to change the order of the strings in strings.xml</li></ul><p>As the translations arrived i realised that you can’t copy the localized strings as a whole list into the Translation Editor. Only string by string. Ok, agreed that this would blow up the scope of the editor. But what now? <br>Copying string by string? 374 strings for 7 languages? Oh No! <br>Looking for some tools that can do the job? Found some but none of them did really work out of the box. Fix them? Ok, when possible in one hour, but no!<br>Writing a tool by myself? Well, i just started to reactivate my bash and regex knowledge when my treasured colleague <a href="https://medium.com/u/cc6093afa421">Ralph Bergmann</a> gave me <strong>the</strong> solution:</p><ul><li>Given you have an Excel sheet now with two columns. <br>The first with the string identifiers and the second with the localized strings (for one language for now, but you can just hide the others).</li><li>In your Excel sheet add new columns left and right to the one with the string identifiers.</li><li>In the left column add <strong>&lt;string name=” </strong>at each row</li><li>In the right column add <strong>“&gt;</strong></li><li>In the column right to the localized strings add <strong>&lt;/string&gt;</strong></li><li>(Ok, now you already know how this will end up)</li><li>Copy the whole block in your localized strings.xml and that’s it (almost, because in my case i needed to remove some tab characters here and there. Find &amp; replace did the job</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a6510ad45c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/karlmax-berlin/android-workaday-life-1-adding-lots-of-localized-in-app-strings-1a6510ad45c2">Localizing Android in-app strings without using Phrase</a> was originally published in <a href="https://medium.com/karlmax-berlin">Karlmax Berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sub-modules for Xcode]]></title>
            <link>https://medium.com/karlmax-berlin/sub-modules-for-xcode-acb6b1e5f567?source=rss----c35956f199fa---4</link>
            <guid isPermaLink="false">https://medium.com/p/acb6b1e5f567</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[submodules]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Ralph Bergmann]]></dc:creator>
            <pubDate>Mon, 01 Feb 2021 00:26:33 GMT</pubDate>
            <atom:updated>2023-05-05T09:06:23.984Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been developing software for around 20 years — sometimes for myself, but mostly for clients. For me, it’s much more than a job: it’s fun to solve a problem with elegant and beautiful code. And, of course, you sleep so much better when it’s also maintainable, testable, and reusable — all those fancy buzzwords!</p><p>However, over any project&#39;s lifespan, the development team usually changes. Your client might ask for new features, while libraries are often updated or become deprecated. To carry out these maintenance tasks, a good project architecture is vital. Otherwise, you spend too much time troubleshooting tasks. When the budget runs out, both you and your boss will be frustrated — your client, too, when you don’t make the deadline.</p><p>As a good developer, you will be familiar with <a href="https://twitter.com/unclebobmartin">Uncle Bob</a>’s <a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html">Clean Architecture</a>. In short, this architecture involves splitting your code into modules.</p><p>For Android developers, splitting the project into sub-modules is such a simple task — just ask Android Studio (or IntelliJ IDEA, I’m not sure if other IDEs also have such a feature) to <a href="https://developer.android.com/studio/projects/add-app-module">create a sub-module</a>.</p><p>But how do you split an Xcode project into modules? Well, that’s exactly what I’m going to show you here.</p><h3><strong>Let’s start</strong></h3><p>Open Xcode and create a new, empty workspace. You can’t do this from the Xcode Welcome screen, but you can use the ⌃ ⌘ N (control + command + n) shortcut. Create a new empty folder and call it modules. You can choose a different name, but for this article, I will use modules.</p><p>Add a new project to this workspace with ⇧ ⌘ N (shift + command + n). In the opening dialog, select the iOS App template and call it main.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*vRqspmlQs51jqQ3lXUWd1Q@2x.png" /></figure><p>Make sure you create it in the modules folder and also choose to add it to the app workspace and app group.</p><p>Add another new project, but now select the iOS Framework template and call it core. Create this in the modules folder too and also add it to the app workspace and app group.</p><p>Your folder structure should now look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*JMI3Nevakm-aWnYDEva2RA@2x.png" /></figure><h3><strong>Link it together</strong></h3><p>It’s now time to link the core project/module into the main project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xnaAOMrM_ikVM-SCHjLm9w@2x.png" /></figure><p>Select the main target of the main project and drag and drop the core.framework into the Frameworks, Libraries, and Embedded Content section.</p><h3>A simple test</h3><p>To test it, create a new Swift File (⌘ N) in the core project with this simple method:</p><pre>import Foundation<br><br>public func name() -&gt; String {<br>    return &quot;Ralph&quot;<br>}<br>@ralph-bergmann</pre><p>In the main project, change the ContentView.swift. Add the import core statement and call the name() method:</p><pre>import SwiftUI<br>import core<br><br>struct ContentView: View {<br>    var body: some View {<br>        Text(&quot;Hello, \(name())!&quot;).padding()<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*qW9n5JhIEBRDIbQR0U4yHg@2x.png" /></figure><p>Xcode may display an error regarding the minimum deployment target. To fix this, change it to 13.0 in both main and core projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*if8SSy6Vr0NlsxDaQyx0sQ@2x.png" /></figure><h3>Add dependencies</h3><p>Right now, I’m using <a href="https://cocoapods.org/">CocoaPods</a> for dependency management because I’m not so familiar with <a href="https://developer.apple.com/documentation/swift_packages">Swift Packages</a>.</p><p>In the modules folder, create a Podfile file with this content and call pod install.</p><pre>workspace &#39;app.xcworkspace&#39;<br>platform :ios, &#39;13.0&#39;<br>use_frameworks!<br><br>def core_pods<br>  pod &#39;SwiftDate&#39;, &#39;~&gt; 6.3.1&#39;<br>end<br><br>def main_pods<br>  # add pods for the main target here<br>end<br><br>target &#39;core&#39; do<br>  project &#39;core/core.xcodeproj&#39;<br>  <br>  core_pods<br>end<br><br>target &#39;main&#39; do<br>  project &#39;main/main.xcodeproj&#39;<br>  <br>  core_pods<br>  main_pods<br>end</pre><p>The pod install command initializes CocoaPods for this workspace (because we haven’t done that so far) and adds the SwiftDate pod as a dependency on the core project.</p><p>We can now use SwiftDate (I only use this to show how to add a dependency). Change the ContentView.swift and Name.swift file in the core project as follows:</p><pre>import SwiftUI<br>import core<br><br>struct ContentView: View {<br>    var body: some View {<br>        Text(&quot;Today in one year is: \(nextYear())&quot;).padding()<br>    }<br>}<br><br>struct ContentView_Previews: PreviewProvider {<br>    static var previews: some View {<br>        ContentView()<br>    }<br>}</pre><pre>import Foundation<br>import SwiftDate<br><br><br>public func nextYear() -&gt; String {<br>    let nextYear = (Date() + 1.years)<br>    return nextYear.weekdayName(.default)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*Gs_RL_BclisWqvIj6DQ2mg@2x.png" /></figure><h3>Done</h3><p>You can find the complete project at:</p><p><a href="https://github.com/ralph-bergmann/xcode-submodules">GitHub - ralph-bergmann/xcode-submodules</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acb6b1e5f567" width="1" height="1" alt=""><hr><p><a href="https://medium.com/karlmax-berlin/sub-modules-for-xcode-acb6b1e5f567">Sub-modules for Xcode</a> was originally published in <a href="https://medium.com/karlmax-berlin">Karlmax Berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Tale of Xcode Server]]></title>
            <link>https://medium.com/karlmax-berlin/a-tale-of-xcode-server-d1649a4141b3?source=rss----c35956f199fa---4</link>
            <guid isPermaLink="false">https://medium.com/p/d1649a4141b3</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[xcode-server]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[ios-development]]></category>
            <dc:creator><![CDATA[Rui]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 08:54:54 GMT</pubDate>
            <atom:updated>2021-01-07T08:54:54.735Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="https://karlmax-berlin.com/">Karlmax Berlin</a> we’re transitioning our iOS Continuous Integration (CI) and Continuous Delivery (CD) workflow to Xcode Server.</p><p>In this blog post, I’ll tell you about our experience with it and mention a few caveats.</p><h3><strong>Before</strong></h3><p>As an agency, we work with different clients. The mobile apps we build are not only distributed internally but also to the clients and their testers. Oftentimes we also coordinate their App Store releases. <br>Behind the scenes, there are quite a few certificates and provisioning profiles to juggle.</p><p>Traditionally, we’ve used Jenkins and App Center / HockeyApp to build and distribute our apps.<br>For iOS, our CI/CD workflow consisted mostly of Fastlane or build scripts, triggered by Jenkins on a dedicated machine.</p><h4><strong>Pain points</strong></h4><ul><li><a href="https://docs.fastlane.tools/actions/match/">Fastlane Match</a> was used to sync certificates and profiles across the team. Configuring it for new projects was quite a time-consuming ordeal. Maybe we were just missing internal documentation for it. The few of us who had worked with it before couldn’t remember all the details of how to set it up consistently. Our Fastfiles were outdated and in need of a revision to follow current best practices.</li><li>Build scripts are harder to maintain than Fastlane and are also harder to reason about, at least to someone new to them. Using this approach, certificates and profiles still had to be moved around manually. <br>The huge raw build log isn’t fun to inspect. A syntax highlighting plugin could certainly improve that, but we didn’t look for one.</li></ul><p>We had a meeting to discuss the state of affairs in our iOS CI/CD workflow and propose alternatives. Some of us had heard of Xcode Server before but hadn’t played with it yet.<br>The two main action items from that meeting were:</p><ul><li>Use a dedicated Apple ID for all CI/CD tasks.</li><li>Try out Xcode Server.</li></ul><h3><strong>The Road to Xcode Server</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvSL5FUEcU4ofHY-htluqQ.png" /><figcaption>WWDC 2017: Automatic Signing being introduced.</figcaption></figure><p>Apple <a href="https://developer.apple.com/videos/play/wwdc2017/403/">added support for automatic signing</a> to Xcode Server in 2017 and bought <a href="https://buddybuild.com/">BuddyBuild</a> sometime after. <br>Automatic code signing and device provisioning was the main selling point for us. On top of that, Xcode Server gives you a nice user interface.<br>It also has an <a href="https://developer.apple.com/library/archive/documentation/Xcode/Conceptual/XcodeServerAPIReference/index.html">API</a> that allows integrating it with our own tools and processes, shall we ever need it.<br>Xcode Server features a <a href="https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/MonitorBotsandDownloadProductsfromaWebBrowser.html#//apple_ref/doc/uid/TP40013292-CH10-SW1">web interface</a> with simplified reports and the possibility to download the build artefacts — .xcarchive and .ipa files. Using the web interface, other team members can trigger builds without needing Xcode on their machine.<br>Conceptually, Xcode Server bots are similar to Jenkins jobs and integrations similar to Jenkins builds.</p><p>We were convinced. Time to get our hands on it!</p><h3><strong>Configuration</strong></h3><p>I’ll keep it short as there are already several resources out there with instructions on how to set it up.</p><ul><li>You need to activate it under <strong>Xcode </strong>&gt;<strong> Preferences </strong>&gt;<strong> Server &amp; Bots</strong> on the machine where your CI/CD is.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UKCl_wDfzxbDfqFVhpDD3Q.png" /><figcaption>Server &amp; Bots tab in Xcode 12.</figcaption></figure><ul><li>Each developer shall add an Xcode Server account to their own Xcode, in order to create and configure bots, trigger integrations and see the results. Bots are saved on the machine with Xcode Server.</li><li>You can easily add pre-integration and post-integration scripts to carry out the tasks required by your project. <br>An example of a pre-integration script could be running pod install, if your project uses CocoaPods.<br>Post-integration script examples: uploading to App Store Connect / TestFlight (using <a href="https://help.apple.com/itc/apploader/#/apdATD1E53-D1E1A1303-D1E53A1126">altool</a>) and posting the integration results to Slack.</li></ul><p>If you’ve never configured Xcode Server before, you might want to check out a recent <a href="https://www.raywenderlich.com/12258400-xcode-server-for-ios-getting-started">tutorial by Adam Rush on raywenderlich.com</a>.</p><h3><strong>Caveats</strong></h3><h4><strong>Xcode upgrades</strong></h4><p>After upgrading Xcode to a newer version, Xcode Server also needs to be upgraded before new integrations are run.<br>Besides that, a bot can be configured to perform a test integration after each upgrade, to isolate any upgrades which might break an integration. However, before enabling this, you might want to check if the integration won’t have unintended consequences, such as uploading a new build to the client’s App Store Connect.</p><h4><strong>Building from a specific git branch</strong></h4><p>If you schedule an integration to run after new commits appear on a remote repository, it should run on the same branch you have checked out locally. However, this behaviour has changed between Xcode versions. You could add a pre-integration script with git checkout your-target-branch to prevent building from an unexpected branch.</p><h4><strong>Exporting to App Store Connect</strong></h4><p>You’ll need to provide a custom export options plist with method set as app-store. It’s one of the export options in the build configuration, inside <strong>Actions</strong> &gt; <strong>Archive</strong>.<br> This is all you need if you have the necessary permissions to sign the app and automatic signing is enabled for this bot.<br> Example ExportOptions.plist for automatic signing:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;<br>&lt;plist version=&quot;1.0&quot;&gt;<br>&lt;dict&gt;<br>    &lt;key&gt;method&lt;/key&gt;<br>    &lt;string&gt;app-store&lt;/string&gt;<br>    &lt;key&gt;uploadSymbols&lt;/key&gt;<br>    &lt;true/&gt;<br>&lt;/dict&gt;<br>&lt;/plist&gt;</pre><p>The option to upload symbols can also be configured, as included in the example.</p><h4><strong>Code signing and provisioning</strong></h4><p>If you’re migrating an existing project and would like to take advantage of Xcode Server’s automatic code signing, you’ll need to ensure its build settings contain:</p><ul><li>A Code Signing Identity for automatic signing (<em>e.g.</em> iOS Developer or Apple Developer)</li><li>Automatic Code Signing Style</li><li>Automatic Provisioning Profile</li></ul><p>In case you must use manual code signing and device provisioning: in the custom export options plist you’ll need to define the signing style as manual and specify the team id, signing certificate, and provisioning profile. You can then upload both the certificate and the profile from your machine to Xcode Server, all via the bot configuration pane.</p><h3><strong>Final Remarks</strong></h3><p>The experiment with Xcode Server went quite well. A few of us have already successfully migrated projects to it!</p><p>Xcode Server isn’t as widely used as Fastlane and Jenkins, therefore there are fewer ready-made integrations with other services. Luckily, the tasks we currently need can be carried out by relatively simple post-integration scripts. <br>Depending on your requirements, you might also have to write a few scripts 🙀. The good news is you can write them in Swift! 😎<br>Alternatively, Fastlane could also be used for the post-integration part of the process, leaving code signing, device provisioning, and app export to Xcode Server.</p><p>Considering our workflow, using both Jenkins and Xcode Server — although possible — would be redundant. Thus, we’re slowly transitioning away from Jenkins for iOS apps.<br>The downside is that we don’t have a central place to monitor the CI and CD for both our Android and iOS apps anymore.</p><p>Updating the existing tools and writing good documentation would probably have yielded similar results. However, when we met to discuss improvements to our iOS CI and CD, most of us seemed interested in checking out Xcode Server. After all, who doesn’t enjoy the opportunity to experiment with a promising tool?</p><p>We’re excited about the future of Xcode Server!</p><h3><strong>Further reading</strong></h3><p>These resources have been useful during the process.</p><ul><li><a href="https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/adopt_continuous_integration.html">Apple’s documentation</a></li><li><a href="https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/EnvironmentVariableReference.html">Xcode Server Environment Variable Reference</a></li><li><a href="https://medium.com/xcblog">XCBlog</a></li><li><a href="https://honzadvorsky.com/pages/xcode_server_tutorials/">Honza Dvorsky’s 2015 write-ups</a></li></ul><p><em>This article was written in December 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1649a4141b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/karlmax-berlin/a-tale-of-xcode-server-d1649a4141b3">A Tale of Xcode Server</a> was originally published in <a href="https://medium.com/karlmax-berlin">Karlmax Berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Versioning with Flutter]]></title>
            <link>https://medium.com/karlmax-berlin/versioning-with-flutter-299869e68af4?source=rss----c35956f199fa---4</link>
            <guid isPermaLink="false">https://medium.com/p/299869e68af4</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Ralph Bergmann]]></dc:creator>
            <pubDate>Wed, 02 Dec 2020 11:09:44 GMT</pubDate>
            <atom:updated>2023-05-05T09:17:40.843Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Please note: This is my first article since I left university. So please be patient.<br>2nd note: My Java/Kotlin/Swift/Dart is much better than my English ;-)</blockquote><blockquote><strong>Update January 31th, 2019</strong></blockquote><p>Does it bother you to increase the version in the Android as well as in the iOS part again and again? You can be helped.</p><p>Every time you want to create a new version you have to increase the build number in Android as well as in iOS: You have to modify the app/build.gradle file and the Info.plist file.</p><p>Would it be nice to have just one place to do that?</p><blockquote>T̶h̶e̶ ̶f̶o̶l̶l̶o̶w̶i̶n̶g̶ ̶d̶e̶p̶e̶n̶d̶s̶ ̶o̶n̶ ̶#̶1̶6̶8̶5̶7̶.̶ ̶C̶u̶r̶r̶e̶n̶t̶l̶y̶,̶ ̶i̶t̶ ̶i̶s̶n̶’̶t̶ ̶m̶e̶r̶g̶e̶d̶,̶ ̶s̶o̶ ̶y̶o̶u̶ ̶h̶a̶v̶e̶ ̶t̶o̶ ̶w̶a̶i̶t̶ ̶a̶ ̶l̶i̶t̶t̶l̶e̶ ̶b̶i̶t̶.̶ ̶B̶u̶t̶ ̶a̶s̶ ̶w̶e̶ ̶s̶a̶y̶ ̶i̶n̶ ̶G̶e̶r̶m̶a̶n̶y̶:̶ ̶V̶o̶r̶f̶r̶e̶u̶d̶e̶ ̶i̶s̶t̶ ̶d̶i̶e̶ ̶s̶c̶h̶ö̶n̶s̶t̶e̶ ̶F̶r̶e̶u̶d̶e̶ ̶(̶I̶ ̶h̶a̶t̶ ̶t̶h̶i̶s̶ ̶s̶e̶n̶t̶e̶n̶c̶e̶.̶ ̶P̶a̶r̶e̶n̶t̶s̶ ̶t̶e̶l̶l̶ ̶t̶h̶i̶s̶ ̶t̶o̶ ̶t̶h̶e̶i̶r̶ ̶c̶h̶i̶l̶d̶’̶s̶ ̶b̶e̶f̶o̶r̶e̶ ̶C̶h̶r̶i̶s̶t̶m̶a̶s̶ ̶w̶h̶e̶n̶ ̶t̶h̶e̶ ̶c̶h̶i̶l̶d̶r̶e̶n̶ ̶c̶a̶n̶’̶t̶ ̶w̶a̶i̶t̶ ̶t̶o̶ ̶g̶e̶t̶ ̶t̶h̶e̶ ̶p̶r̶e̶s̶e̶n̶t̶s̶)̶.̶</blockquote><p>O̶k̶a̶y̶,̶ ̶w̶e̶ ̶a̶s̶s̶u̶m̶e̶ ̶i̶t̶ ̶i̶s̶ ̶m̶e̶r̶g̶e̶d̶.̶</p><p>If you create a new Flutter project the pubspec.yaml file has a version property like this:</p><pre>name: hello<br>description: A new Flutter project.<br>version: 1.0.0+1<br>dependencies:<br>  flutter:<br>    sdk: flutter<br>...</pre><p>Flutter uses this value to set the version in both Android and iOS for you. You only need to call flutter run or flutter build or press the play button in IntelliJ / Android Studio / the IDE of your choice.</p><h3>The Format</h3><p>Flutter expects an exact format of the version property.</p><p>It has two parts separated by a +. The first part is the build name (versionName Android / CFBundleShortVersionString iOS), and the second part is the build number (versionCode Android / CFBundleVersion iOS).</p><p>The build name can have up to 3 integers separated by dots. The build number is just one integer.</p><h3>How to modify them?</h3><p>You can still edit the pubspec.yaml file by hand, but sometimes you need a way to modify them automatically, for example, when your CI builds a new version.</p><p>To change the version automatically, you have two options —-build-name and --build-number. These two options are options of the flutter build command:</p><pre>$ flutter build apk --build-name=1.0.3<br>$ flutter build apk --build-number=3<br>$ flutter build apk --build-name=1.0.3 --build-number=3</pre><p>I use <a href="https://fastlane.tools/">Fastlane</a> to do my CI builds. My fastfile looks like this:</p><pre>lane :alphaBuild do<br>  # Return the number of commits in current git branch<br>  build_number = number_of_commits()<br>  Dir.chdir &quot;..&quot; do<br>    sh(&quot;flutter&quot;, &quot;packages&quot;, &quot;get&quot;)<br>    sh(&quot;flutter&quot;, &quot;clean&quot;)<br>    sh(&quot;flutter&quot;, &quot;build&quot;, &quot;apk&quot;, &quot;--build-number=#{build_number}&quot;)<br>  end<br>end</pre><h3>How to update an old Flutter project?</h3><p>You can also do the above with an old Flutter project, but you need to make some changes.</p><h4>Flutter Part</h4><p>All you have to do is to add the version property to your pubspec.yaml file. It should look like this:</p><pre>name: hello<br>description: A new Flutter project.<br>version: 1.0.0+1         # add this<br>dependencies:<br>  flutter:<br>    sdk: flutter<br>...</pre><h4>Android Part</h4><p>Every time you call flutter run or flutter build Flutter updates the local.properties file. You only need to use the values in your app/build.gradle file.</p><p>To do that, modify your app/build.gradle file that it looks like this:</p><pre>def localProperties = new Properties()<br>def localPropertiesFile = rootProject.file(&#39;local.properties&#39;)<br>if (localPropertiesFile.exists()) {<br>    localPropertiesFile.withReader(&#39;UTF-8&#39;) { reader -&gt;<br>        localProperties.load(reader)<br>    }<br>}<br><br>def flutterRoot = localProperties.getProperty(&#39;flutter.sdk&#39;)<br>if (flutterRoot == null) {<br>    throw new GradleException(&quot;Flutter SDK not found. Define location with flutter.sdk in the local.properties file.&quot;)<br>}<br><br>def flutterVersionCode = localProperties.getProperty(&#39;flutter.versionCode&#39;)<br>if (flutterVersionCode == null) {<br>    throw new GradleException(&quot;versionCode not found. Define flutter.versionCode in the local.properties file.&quot;)<br>}<br><br>def flutterVersionName = localProperties.getProperty(&#39;flutter.versionName&#39;)<br>if (flutterVersionName == null) {<br>    throw new GradleException(&quot;versionName not found. Define flutter.versionName in the local.properties file.&quot;)<br>}<br><br>apply plugin: &#39;com.android.application&#39;<br>apply from: &quot;$flutterRoot/packages/flutter_tools/gradle/flutter.gradle&quot;<br><br>android {<br>    compileSdkVersion 27<br><br>    lintOptions {<br>        disable &#39;InvalidPackage&#39;<br>    }<br><br>    defaultConfig {<br>        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).<br>        applicationId &quot;com.example.hello&quot;<br>        minSdkVersion 16<br>        targetSdkVersion 27<br>        versionCode flutterVersionCode.toInteger()<br>        versionName flutterVersionName<br>        testInstrumentationRunner &quot;android.support.test.runner.AndroidJUnitRunner&quot;<br>    }<br><br>    buildTypes {<br>        release {<br>            // TODO: Add your own signing config for the release build.<br>            // Signing with the debug keys for now, so `flutter run --release` works.<br>            signingConfig signingConfigs.debug<br>        }<br>    }<br>}</pre><p>Read the values from the local.properties file (lines 14 to 22) and use them (lines 39 and 40).</p><h4>iOS Part</h4><p>flutter run and flutter build updates the Generated.xcconfig file too, just use its values.</p><p>Change the CFBundleShortVersionString value to $(FLUTTER_BUILD_NAME) (line 18) and the CFBundleVersion value to $(FLUTTER_BUILD_NUMBER) (line 21) in the info.plist file.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;<br>&lt;plist version=&quot;1.0&quot;&gt;<br>&lt;dict&gt;<br> &lt;key&gt;CFBundleDevelopmentRegion&lt;/key&gt;<br> &lt;string&gt;en&lt;/string&gt;<br> &lt;key&gt;CFBundleExecutable&lt;/key&gt;<br> &lt;string&gt;$(EXECUTABLE_NAME)&lt;/string&gt;<br> &lt;key&gt;CFBundleIdentifier&lt;/key&gt;<br> &lt;string&gt;$(PRODUCT_BUNDLE_IDENTIFIER)&lt;/string&gt;<br> &lt;key&gt;CFBundleInfoDictionaryVersion&lt;/key&gt;<br> &lt;string&gt;6.0&lt;/string&gt;<br> &lt;key&gt;CFBundleName&lt;/key&gt;<br> &lt;string&gt;hello&lt;/string&gt;<br> &lt;key&gt;CFBundlePackageType&lt;/key&gt;<br> &lt;string&gt;APPL&lt;/string&gt;<br> &lt;key&gt;CFBundleShortVersionString&lt;/key&gt;<br> &lt;string&gt;$(FLUTTER_BUILD_NAME)&lt;/string&gt;<br> &lt;key&gt;CFBundleSignature&lt;/key&gt;<br> &lt;string&gt;????&lt;/string&gt;<br> &lt;key&gt;CFBundleVersion&lt;/key&gt;<br> &lt;string&gt;$(FLUTTER_BUILD_NUMBER)&lt;/string&gt;<br> &lt;key&gt;LSRequiresIPhoneOS&lt;/key&gt;<br> &lt;true/&gt;<br> &lt;key&gt;UILaunchStoryboardName&lt;/key&gt;<br> &lt;string&gt;LaunchScreen&lt;/string&gt;<br> &lt;key&gt;UIMainStoryboardFile&lt;/key&gt;<br> &lt;string&gt;Main&lt;/string&gt;<br> &lt;key&gt;UIRequiredDeviceCapabilities&lt;/key&gt;<br> &lt;array&gt;<br>  &lt;string&gt;arm64&lt;/string&gt;<br> &lt;/array&gt;<br> &lt;key&gt;UISupportedInterfaceOrientations&lt;/key&gt;<br> &lt;array&gt;<br>  &lt;string&gt;UIInterfaceOrientationPortrait&lt;/string&gt;<br>  &lt;string&gt;UIInterfaceOrientationLandscapeLeft&lt;/string&gt;<br>  &lt;string&gt;UIInterfaceOrientationLandscapeRight&lt;/string&gt;<br> &lt;/array&gt;<br> &lt;key&gt;UISupportedInterfaceOrientations~ipad&lt;/key&gt;<br> &lt;array&gt;<br>  &lt;string&gt;UIInterfaceOrientationPortrait&lt;/string&gt;<br>  &lt;string&gt;UIInterfaceOrientationPortraitUpsideDown&lt;/string&gt;<br>  &lt;string&gt;UIInterfaceOrientationLandscapeLeft&lt;/string&gt;<br>  &lt;string&gt;UIInterfaceOrientationLandscapeRight&lt;/string&gt;<br> &lt;/array&gt;<br> &lt;key&gt;UIViewControllerBasedStatusBarAppearance&lt;/key&gt;<br> &lt;false/&gt;<br>&lt;/dict&gt;<br>&lt;/plist&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*8PdkGSbE9ESXTrLRVzoQEA.png" /></figure><p>Open the project in Xcode, select the Build Settings tab of the Runner target and search for versioning. Change the value of Current Project Version to $(FLUTTER_BUILD_NUMBER).</p><h3>Bonus</h3><blockquote>T̶h̶e̶ ̶f̶o̶l̶l̶o̶w̶i̶n̶g̶ ̶d̶e̶p̶e̶n̶d̶s̶ ̶o̶n̶ ̶#̶1̶6̶9̶3̶4̶.̶ ̶C̶u̶r̶r̶e̶n̶t̶l̶y̶,̶ ̶i̶t̶ ̶i̶s̶n̶’̶t̶ ̶m̶e̶r̶g̶e̶d̶,̶ ̶s̶o̶ ̶y̶o̶u̶ ̶h̶a̶v̶e̶ ̶t̶o̶ ̶w̶a̶i̶t̶ ̶a̶ ̶l̶i̶t̶t̶l̶e̶ ̶b̶i̶t̶.̶ ̶B̶u̶t̶ ̶a̶s̶ ̶w̶e̶ ̶s̶a̶y̶ ̶i̶n̶ ̶G̶e̶r̶m̶a̶n̶y̶̶…</blockquote><blockquote><strong>It was never merged, but you can use the </strong><a href="https://pub.dartlang.org/packages/package_info"><strong>package_info</strong></a><strong> plugin instead.</strong></blockquote><p>Now that our Flutter project knows the version it would be nice to access it to show it somewhere, in an <a href="https://docs.flutter.io/flutter/material/AboutListTile-class.html">about dialog</a> for example.</p><p>With <a href="https://github.com/flutter/flutter/pull/16934">#16934</a> Flutter generates a lib/build_config.g.dart file which looks like this:</p><pre>// GENERATED CODE - DO NOT MODIFY BY HAND<br><br>class BuildConfig {<br>  static const bool kDebug = true;<br>  static const String kModeName = &quot;debug&quot;;<br>  static const String kFlavor = null;<br>  static const String kVersionName = &quot;1.0.0&quot;;<br>  static const int kVersionNumber = 1;<br>}</pre><p>You can now easily use it to show the version or to do other fancy things depending on the build, for example, if it is a debug build or which flavor was build.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=299869e68af4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/karlmax-berlin/versioning-with-flutter-299869e68af4">Versioning with Flutter</a> was originally published in <a href="https://medium.com/karlmax-berlin">Karlmax Berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>