Compare commits
18 commits
Author | SHA1 | Date | |
---|---|---|---|
a2c5d60e17 | |||
dc86fdeb8b | |||
61c53c1fe4 | |||
f6261aebcd | |||
9a75e30ae0 | |||
452082de2a | |||
f1dcecf971 | |||
51734be9f8 | |||
1c4c210091 | |||
8785107ea5 | |||
bf535476ec | |||
07ab6c4ab1 | |||
7833f70173 | |||
6059e20bb5 | |||
b9b9e32b8b | |||
703e34f0b4 | |||
033219169b | |||
1a1b53aaa6 |
9 changed files with 150 additions and 43 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -2,4 +2,8 @@ apk/ToyKey.keystore
|
||||||
apk/obj
|
apk/obj
|
||||||
apk/obj/*
|
apk/obj/*
|
||||||
apk/bin/*
|
apk/bin/*
|
||||||
|
apk/result
|
||||||
|
apk/result/
|
||||||
|
apk/result/*
|
||||||
apk/bin/!.gitkeep
|
apk/bin/!.gitkeep
|
||||||
|
/example.app.apk
|
||||||
|
|
|
@ -19,6 +19,7 @@ ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk/"
|
||||||
#ENTRYPOINT bash -c 'sleep 10000'
|
#ENTRYPOINT bash -c 'sleep 10000'
|
||||||
ENV LIBRARY_PATH="$LIBRARY_PATH:$BUILD_TOOLS_LATEST/lib"
|
ENV LIBRARY_PATH="$LIBRARY_PATH:$BUILD_TOOLS_LATEST/lib"
|
||||||
ARG YESACCEPT=n
|
ARG YESACCEPT=n
|
||||||
|
RUN test "$YESACCEPT" = "y" || { printf "\033[31;1;4m%s\n%s\033[0m " "FAILED TO BUILD CONTAINER: You did not ACCEPT THE UPSTREAM LICENSE" " -> export YESACCEPT=y" >&2; exit 1; }
|
||||||
RUN echo you selected to accept the licenses/TOS
|
RUN echo you selected to accept the licenses/TOS
|
||||||
RUN echo "$YESACCEPT" | sdkmanager --install "build-tools;33.0.2"
|
RUN echo "$YESACCEPT" | sdkmanager --install "build-tools;33.0.2"
|
||||||
RUN echo "$YESACCEPT" | sdkmanager --install "platforms;android-33"
|
RUN echo "$YESACCEPT" | sdkmanager --install "platforms;android-33"
|
||||||
|
|
14
Makefile
14
Makefile
|
@ -3,33 +3,25 @@
|
||||||
all: build install
|
all: build install
|
||||||
|
|
||||||
build:
|
build:
|
||||||
docker-compose run compile
|
docker-compose run --rm compile
|
||||||
|
ln -sf apk/result/example.app.apk ./; test -e ./example.app.apk || rm ./example.app.apk
|
||||||
|
|
||||||
install:
|
install:
|
||||||
adb install -r ./apk/example.app.apk
|
adb install -r ./example.app.apk
|
||||||
|
|
||||||
.PHONY: clean-all
|
.PHONY: clean-all
|
||||||
clean-all: clean-docker clean-apk
|
clean-all: clean-docker clean-apk
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean-docker
|
.PHONY: clean-docker
|
||||||
clean-docker:
|
clean-docker:
|
||||||
rm docker-compose-build.log || true
|
rm docker-compose-build.log || true
|
||||||
docker-compose down --remove-orphans --rmi all
|
docker-compose down --remove-orphans --rmi all
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean-apk
|
.PHONY: clean-apk
|
||||||
clean-apk:
|
clean-apk:
|
||||||
cd apk && $(MAKE) clean
|
cd apk && $(MAKE) clean
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
apk: apk/app.apk
|
|
||||||
true
|
|
||||||
|
|
||||||
apk/app.apk: docker-compose-build.log
|
|
||||||
docker-compose run --rm compile
|
|
||||||
|
|
||||||
docker-compose-build.log: Dockerfile docker-compose.yml
|
docker-compose-build.log: Dockerfile docker-compose.yml
|
||||||
docker-compose down --remove-orphans --rmi all
|
docker-compose down --remove-orphans --rmi all
|
||||||
BUILDKIT_PROGRESS=plain docker-compose build | tee docker-compose-build.log
|
BUILDKIT_PROGRESS=plain docker-compose build | tee docker-compose-build.log
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
# Repo allowing -in a KISS way- to create a containered way to build an Android App APK
|
# Repo allowing -in a KISS way- to create a containered way to build an Android App APK
|
||||||
|
|
||||||
|
|
||||||
|
## changelog
|
||||||
|
|
||||||
|
* using https://android.googlesource.com/platform/cts/+/android-7.1.1_r13/tests/tests/webkit/src/android/webkit/cts/PostMessageTest.java derived
|
||||||
|
webmessage to send data to Javascript/Webview from Java (using a timer)
|
||||||
## brach `no-res.xml`
|
## brach `no-res.xml`
|
||||||
|
|
||||||
this branch features the exmaple.app to not require the compoletely bogus unneeded requirement
|
this branch features the exmaple.app to not require the compoletely bogus unneeded requirement
|
||||||
|
@ -27,7 +32,7 @@ This will generate the APK file `./apk/example.app.apk`
|
||||||
|
|
||||||
this can be installed via `adb`
|
this can be installed via `adb`
|
||||||
```
|
```
|
||||||
adb install -r ./apk/example.app.apk
|
adb install -r ./example.app.apk
|
||||||
# or alternative type
|
# or alternative type
|
||||||
make install
|
make install
|
||||||
```
|
```
|
||||||
|
|
|
@ -5,9 +5,24 @@
|
||||||
android:versionName="1.0">
|
android:versionName="1.0">
|
||||||
<uses-sdk android:minSdkVersion="30"
|
<uses-sdk android:minSdkVersion="30"
|
||||||
android:targetSdkVersion="33"/>
|
android:targetSdkVersion="33"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET">
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
</uses-permission>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<!-- android:maxSdkVersion="integer" /> -->
|
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_MEDIA"/>
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
|
||||||
|
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
|
||||||
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
|
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
|
||||||
<activity android:name="app.example.ExampleApp"
|
<activity android:name="app.example.ExampleApp"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|
25
apk/Makefile
25
apk/Makefile
|
@ -14,29 +14,34 @@ all: build
|
||||||
.PHONY : deploy
|
.PHONY : deploy
|
||||||
.PHONY : clean
|
.PHONY : clean
|
||||||
|
|
||||||
build : ./bin/example.app.apk
|
build : ./result/example.app.apk
|
||||||
ln -sf ./bin/example.app.apk ./example.app.apk
|
true
|
||||||
|
|
||||||
./bin/example.app.apk : ./bin/signed.apk
|
env:
|
||||||
|
set > set ; env > env
|
||||||
|
./result/example.app.apk : ./result/signed.apk
|
||||||
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/zipalign -v -f 4 $< $@
|
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/zipalign -v -f 4 $< $@
|
||||||
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/apksigner sign --ks ToyKey.keystore --key-pass pass:armena --ks-pass pass:armena $@
|
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/apksigner sign --ks ToyKey.keystore --key-pass pass:armena --ks-pass pass:armena $@
|
||||||
|
|
||||||
./bin/signed.apk : ./bin/unsigned.apk ./ToyKey.keystore
|
./result/signed.apk : ./result/unsigned.apk ./ToyKey.keystore ./result
|
||||||
jarsigner -verbose -keystore ./ToyKey.keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey
|
jarsigner -verbose -keystore ./ToyKey.keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey
|
||||||
|
|
||||||
./bin/unsigned.apk : ./bin/classes.dex
|
./result:
|
||||||
|
mkdir -p "$@"
|
||||||
|
|
||||||
|
./result/unsigned.apk : ./bin/classes.dex ./result
|
||||||
rm -rvf "$@"
|
rm -rvf "$@"
|
||||||
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/aapt package -v -u -f -M ./AndroidManifest.xml -S ./res \
|
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/aapt package -v -u -f -M ./AndroidManifest.xml -S ./res \
|
||||||
-I $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar -F $@ ./bin
|
-I $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar -A ./assets -F $@ ./bin
|
||||||
|
|
||||||
./bin/classes.dex : ./obj/app/example/ExampleApp.class
|
./bin/classes.dex : ./obj/app/example/ExampleApp.class ./obj/app/example/ExampleApp$$1.class
|
||||||
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/d8 $(shell find obj -name '*.class') --lib $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar --output bin
|
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/d8 ./obj/app/example/*.class --lib $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar --output bin
|
||||||
|
|
||||||
./src/app/example/R.java : $(shell find ./res -type f)
|
./src/app/example/R.java : $(shell find ./res -type f)
|
||||||
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/aapt package -v -f -m -S ./res -J ./src -M ./AndroidManifest.xml \
|
$(ANDROID_HOME)/build-tools/$(ANDROID_VERSION)/aapt package -v -f -m -S ./res -J ./src -M ./AndroidManifest.xml \
|
||||||
-I $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar
|
-I $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar
|
||||||
|
|
||||||
./obj/app/example/ExampleApp.class : ./src/app/example/ExampleApp.java ./src/app/example/R.java
|
./obj/app/example/ExampleApp.class : ./src/app/example/ExampleApp.java ./src/app/example/R.java
|
||||||
javac -d ./obj -classpath $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar -sourcepath ./src $<
|
javac -d ./obj -classpath $(ANDROID_HOME)/platforms/$(PLATFORM)/android.jar -sourcepath ./src $<
|
||||||
|
|
||||||
./ToyKey.keystore :
|
./ToyKey.keystore :
|
||||||
|
@ -44,4 +49,4 @@ build : ./bin/example.app.apk
|
||||||
-storepass armena -keypass armena -alias helljniKey -keyalg RSA -v
|
-storepass armena -keypass armena -alias helljniKey -keyalg RSA -v
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ./bin/* ./lib/arm64-v8a/*
|
rm -f ./bin/* ./lib/arm64-v8a/* ./result/*
|
||||||
|
|
21
apk/assets/index.html
Normal file
21
apk/assets/index.html
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<script>
|
||||||
|
window.addEventListener('message',(e)=>{
|
||||||
|
var div = document.createElement('div');
|
||||||
|
div.innerHTML='message'+e.data;
|
||||||
|
document.body.appendChild(div);
|
||||||
|
div.scrollIntoView({ behavior: 'smooth'});
|
||||||
|
},true);
|
||||||
|
window.addEventListener('load',()=>{
|
||||||
|
var div = document.createElement('div');
|
||||||
|
div.innerHTML='JAVASCRIPT works'
|
||||||
|
document.body.appendChild(div);
|
||||||
|
div.scrollIntoView({ behavior: 'smooth'});
|
||||||
|
},false);
|
||||||
|
</script>
|
||||||
|
<a href='https://html5test.co/'>https://html5test.co/</a>
|
||||||
|
<h1> this is html <h1>
|
||||||
|
<h2> this is a h2</h2>
|
||||||
|
<img src='https://wald.alexmahr.de/images/bear.avif'>
|
||||||
|
</html>
|
|
@ -1,33 +1,97 @@
|
||||||
package app.example;
|
package app.example;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.TextView;
|
import android.util.Base64;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.text.method.ScrollingMovementMethod;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
//import android.view.MenuItem;
|
||||||
import android.view.ViewGroup.*;
|
import android.view.ViewGroup.*;
|
||||||
|
import android.widget.*;
|
||||||
|
//import android.widget.TextView;
|
||||||
|
import android.webkit.*;
|
||||||
|
import android.net.Uri;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
//import android.webkit.WebView;
|
||||||
|
//import android.webkit.WebMessage;
|
||||||
|
//import android.webkit.WebMessagePort;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class ExampleApp extends Activity {
|
public class ExampleApp extends Activity {
|
||||||
|
|
||||||
|
private static final String BASE_URI = "https://alexmahr.de";
|
||||||
|
private WebMessagePort port;
|
||||||
|
private void initPort(WebView myWebView) {
|
||||||
|
final WebMessagePort[] channel=myWebView.createWebMessageChannel();
|
||||||
|
port=channel[0];
|
||||||
|
port.setWebMessageCallback(new WebMessagePort.WebMessageCallback() {
|
||||||
|
@Override
|
||||||
|
public void onMessage(WebMessagePort port, WebMessage message) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
myWebView.postWebMessage(new WebMessage("", new WebMessagePort[]{channel[1]}),Uri.parse(BASE_URI));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String readFileFromAssets(String filename) {
|
||||||
|
String filecontents = "";
|
||||||
|
try {
|
||||||
|
InputStream stream = getAssets().open(filename);
|
||||||
|
int filesize = stream.available();
|
||||||
|
byte[] filebuffer = new byte[filesize];
|
||||||
|
stream.read(filebuffer);
|
||||||
|
stream.close();
|
||||||
|
filecontents = new String(filebuffer);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// I <3 java exceptions
|
||||||
|
}
|
||||||
|
return filecontents;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
// creating LinearLayout
|
// this removes the title bar (a ~1cm big strip at the top of the app showing its name
|
||||||
LinearLayout linLayout = new LinearLayout(this);
|
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
// specifying vertical orientation
|
// we create the webview (at least on the android 14 that is a webview that features avif + websockets etc....)
|
||||||
linLayout.setOrientation(LinearLayout.VERTICAL);
|
WebView myWebView = new WebView(this);//activityContext);
|
||||||
// creating LayoutParams
|
// MyJavascriptInterface myJavaScriptInterface = new MyJavascriptInterface(this,myWebView);
|
||||||
LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
// we create a webview (there is also setwebviewclient-vs-setwebchromeclient
|
||||||
// set LinearLayout as a root element of the screen
|
WebViewClient myWebViewClient= new WebViewClient();
|
||||||
setContentView(linLayout, linLayoutParam);
|
myWebView.setWebViewClient(myWebViewClient);
|
||||||
|
// to setup settings
|
||||||
|
WebSettings myWebSettings = myWebView.getSettings();
|
||||||
|
myWebSettings.setBuiltInZoomControls(true);
|
||||||
|
myWebSettings.setDisplayZoomControls(false);
|
||||||
|
myWebSettings.setJavaScriptEnabled(true);
|
||||||
|
myWebView.addJavascriptInterface(this, "myJavaScriptInterface");
|
||||||
|
// load the html from assets file
|
||||||
|
String html = readFileFromAssets("index.html");
|
||||||
|
myWebView.loadDataWithBaseURL(BASE_URI,html, "text/html", "UTF-8",null);
|
||||||
|
//myWebView.loadData(encodedHtml, "text/html", "base64");
|
||||||
|
// alternatively this could be to load a website
|
||||||
|
//myWebView.loadUrl("https://alexmahr.de/ru");
|
||||||
|
setContentView(myWebView);
|
||||||
|
new CountDownTimer(5000, 1000) {
|
||||||
|
public void onTick(long millisUntilFinished) {
|
||||||
|
try{
|
||||||
|
JSONObject MyJSONObject = new JSONObject("{\"json\":[1,2,3],\"something\":\"test\"}");
|
||||||
|
myWebView.postWebMessage(new WebMessage("this is the message"+millisUntilFinished+ " " + MyJSONObject.get("something")),Uri.parse(BASE_URI));
|
||||||
|
} catch( Exception e) { }
|
||||||
|
// mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
|
||||||
|
// myWebView.evaluateJavascript("document.body.innerHTML='SUP "+millisUntilFinished+" all is lost';",null);
|
||||||
|
}
|
||||||
|
|
||||||
LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
public void onFinish() {
|
||||||
|
myWebView.evaluateJavascript("document.body.innerHTML='all is lost';",null);
|
||||||
TextView tv = new TextView(this);
|
}
|
||||||
tv.setText("SUPERVIEalexW");
|
}.start();
|
||||||
tv.setLayoutParams(lpView);
|
}
|
||||||
linLayout.addView(tv);
|
@JavascriptInterface
|
||||||
|
public String toString() {
|
||||||
|
// this.webview.evaluateJavascript("(setTimeout(()=>{document.body.innerHTML='all gone';},2000)()",null);
|
||||||
|
return "this is good";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ services:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
args:
|
args:
|
||||||
YESACCEPT: ${YESACCEPT}
|
YESACCEPT: ${YESACCEPT:-n}
|
||||||
stop_grace_period: 1s
|
stop_grace_period: 1s
|
||||||
volumes:
|
volumes:
|
||||||
- ./apk:/apk
|
- ./apk:/apk
|
||||||
|
|
Loading…
Add table
Reference in a new issue