[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[node8-android] Implementing a new App from scratch

Step by step procedure to implement a new Native Android application using S8 Smalltalk on node8-android platform

NoteIt is NOT the fastest and easy way to build your app.
The best way is to use node8 project and edit/change s8App sample application to meet your requirements.
It is good to do this way because you can use the U8 toolset while developing your app.

Downloading and checking Android Studio installation

  1. Download platform files and samples to make it easy to add contents from sample files
  2. Decompress the zip files in the node8 folder inside your Androd Studio Projects folder
  3. Open the node8 project in Android Studio
  4. Build the application s8App in Android Studio to ensure you have Android Studio configured for development on your android device
  5. Press Debug button in Android Studio to ensure you can debug apps in your device
Uploaded Image: node8AS.jpg


Creating my node8 Application

  1. Create a new Android Studio project
  2. Press [Finish] button
  3. wait for basic application to be created in Android Studio (can take minutes, depending on the contents to be downloaded by Android Studio toolset)
Uploaded Image: myapp1.jpg


Adding node.js and java bindings and default snapshot file

  1. Open a file browser in your Android Studio projects folder
  2. Locate node8/app folder and copy libnode and node subfolders to MyApp8/app project folder
  3. Copy node8/app/CMakeLists.txt file to MyApp8/app
  4. Locate node8/app/src/main folder and copy cpp and assets subfolders to MyApp8/app project folder
  5. Locate node8/app/src/main/java folder and copy org subfolders to MyApp8/app/src/main/java project folder
  6. Edit the contents of file MyApp8/app/src/main/java/MainActivity.javato be the same of node8/app/src/main/java/MainActivity.java (all the file contents except the first line is OK to copy)
  7. Edit MyApp8/app/build.gradle file to match entries in node8/app/build.gradle
    check:
  8. Sync project with gradle files
    The build should be successful
  9. at this point you should find the file default.snapshot.js under assets/s8 (it is the default snapshot of this platform, that implements smalltalk support for app, to open a dialog when you press the settings button on menu at right top border of the screen)
  10. ensure your device is connected and press [debug] button to start the app on the device

Editions made to adapt (Java and C) sources of node8/app to MyApp8/app

  1. Use Android Studio menu Edit/Find/Find in Path to search for string "s8_app"
  2. Use Android Studio menu Edit/Find/Find in Path to search for string "s8.app"


What if something goes wrong?

It can happen that Android Studio require a change (e.g. gradle, project settings, runtimes, java etc...) that makes the app crash at startup. In this cases it is reccomended to ask in our fracebook group to do not reinvent the weel. But remember, that all the code here is MIT licensed, it is under your responsibility to maintain it fresh. Most is implemented in S8 smalltalk so it is working under simple rules that works in all platforms whre S8 is running.

Today (Oct 20, 2020) the clean installation report a library mismatch at startup.
The failure is related with issue in gradle framework.
To avoid the crash it is required to use gradle version 4.0.x (or later)
To set the gradle version, edit the build.gradle file in (Project: MyApp8) to
classpath 'com.android.tools.build:gradle:4.0.2'

And now? what has gone wrong with ACCESS_WIFI_State?

The default app can be debugged remotelly and at startup it need to publish the debugger server. So it requires the Wifi network permision to be enabled.
You can copy/paste all permisions published in node8/app/src/main/AndroidManifest.xml to MyApp8/app/src/main/AndroidManifest.xml
The frameworks we use to build S8 applications edit the permisions list while building the snapshot; you can edit the file manually now; and read on how to add our build frameworks later (on this page).

What we have at this point?

We have a running android application that evaluates an expression when an UI element is selected.
The handling of the event is sent as an expression (a string) to be evaluated by the S8 smalltalk system.
There are other alternatives to interact at all levels of execution (javascript, java, C) to/from S8 smalltalk objects.

The snapshot of S8 system embedded in the application is the default snapshot; the next section covers the aditions you need to make to setup S8 console frameworks to build your image from source files; and edit the changes to produce fast updates of the application.

At startup, your application will have a menu on the top right of the screen with an item "Settings".
Uploaded Image: settings.jpg

When you press the Settings option, an expression is evaluated on Smalltalk side to show the alert dialog.
The alert dialog is implemented exposing a minimal interface to android Alert Dialog.
Uploaded Image: alert.jpg

It is reccomended at this point to invest time reading the implementation of MainActivity.java to learn how the snapshot is loaded and the event is managed on java side to evaluate a Smalltalk expression.

What to do now?

You can modify the application to load snapshot from any file stored in the device. You can also save snapshot at any place; send it to another device or save/load S8 smalltalk modules (.st.js files) on demmand.
It is smalltalk!

You can also build the system using modules that are developed in other platforms (web and/or console) in parallel and load the modules in native format to do not require the Smalltalk compiler at runtime (or make instant loading of modules on demmand).

Our standard way of development with S8 is 100% smalltalk and modular. We save snapshots when we need to make that way, but are not constrained to handling non-readable representations of our objects.
The fileIn and export frameworks of S8 smalltalk are enhanced to produce modular systems, containing methods and objects.
We use to build systems using Console platform in short time (minute or two) recompiling only the required modules that has changed from the time of the last build.
The framework we use to build modular android applications is contained in subfolder "s8" of the node8 project you have already downloaded (part 3 of downloaded files).
The next section explains how it works and how to modify the framework to add your application.

Adding S8 files to start working with S8 Smalltalk

  1. Install the console platform and make "s8vm" executable from path.
  2. Copy the subfolder named "s8" from project node8 to "MyApp8"
  3. Copy the file "s8/app.js" to "myapp8.js"
  4. Edit the file "myapp8.js" to define
    applicationSources = "sources/myapp8/build.st";
  5. Copy the folder "s8/sources/app" to "s8/sources/myapp8"
  6. Edit the ".st" files at "s8/sources/myapp8/" changing "app" to "myapp8" when appropiate (e.g. occurences in "build.st", "net.smalltalking.s8.app.st", etc)

Execute the following command to build the snapshot (note that the snapshot will be stored in the assets of your application)
s8vm.exe --expose-gc --shell myapp8.js build.js

How to debug remotelly this minimal application?

It is easy to connect to a S8 android application with our remote debugger.
  1. Install the U8 Remote debugger as a Chrome extension of your desktop computer.
  2. ensure your application is running on the device
  3. Open Chrome navigator and press the debug button on the home page
    Uploaded Image: u8Debugger.jpg
  4. Enter the local IP address of your android device and press [Connect] button
  5. The inspectables list should open
  6. Select the "Settings" menu option in your application. It will send #halt message
  7. The debugger is paused waiting your assistance while debugging the code running in the S8 smalltalk system.
  8. have fun!

References

Social supportFacebook group
Platformnode8 Platform
Repository U8 - S8 Universe
Collaborative support and media U8 Swiki and S8 media swiki
Building toolsetConsole platform
S8 main storageS8 kernel and frameworks
Debugging toolsU8 Remote Debugger