Skip to content

Commit 6776833

Browse files
committed
feat: support android embedding
1 parent 643958b commit 6776833

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+632
-23
lines changed

build-artifacts/project-template-gradle/settings.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
mavenLocal()
5+
}
6+
}
7+
18
rootProject.name = "__PROJECT_NAME__"
29
include ':app'//, ':runtime', ':runtime-binding-generator'
310

build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ task copyFilesToProjectTemeplate {
260260
from "$TEST_APP_PATH/app/src/main/java/com/tns/internal"
261261
into "$DIST_FRAMEWORK_PATH/app/src/main/java/com/tns/internal"
262262
}
263+
copy {
264+
from "$TEST_APP_PATH/app/src/main/java/com/tns/embedding"
265+
into "$DIST_FRAMEWORK_PATH/app/src/main/java/com/tns/embedding"
266+
}
263267
copy {
264268
from "$BUILD_TOOLS_PATH/static-binding-generator/build/libs/static-binding-generator.jar"
265269
into "$DIST_FRAMEWORK_PATH/build-tools"
@@ -295,6 +299,10 @@ task copyFilesToProjectTemeplate {
295299
from "$TEST_APP_PATH/app/build.gradle"
296300
into "$DIST_FRAMEWORK_PATH/app"
297301
}
302+
copy {
303+
from "$TEST_APP_PATH/app/nativescript.gradle"
304+
into "$DIST_FRAMEWORK_PATH/app"
305+
}
298306
copy {
299307
from "$TEST_APP_PATH/build.gradle"
300308
into "$DIST_FRAMEWORK_PATH"

test-app/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
<application
1111
android:requestLegacyExternalStorage="true"
12-
android:name="com.tns.NativeScriptApplication"
12+
android:name="com.tns.TestNativeScriptApplication"
1313
android:allowBackup="true"
1414
android:icon="@mipmap/ic_launcher"
1515
android:label="@string/app_name"
1616
android:roundIcon="@mipmap/ic_launcher_round"
1717
android:supportsRtl="true"
1818
android:theme="@style/AppTheme">
19-
<activity android:name="com.tns.NativeScriptActivity" android:exported="true">
19+
<activity android:name="com.tns.TestNativeScriptActivity" android:exported="true">
2020
<intent-filter>
2121
<action android:name="android.intent.action.MAIN" />
2222
<category android:name="android.intent.category.LAUNCHER" />

test-app/app/src/main/assets/app/MyActivity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var MyActivity = (function (_super) {
6262

6363
};
6464
MyActivity = __decorate([
65-
JavaProxy("com.tns.NativeScriptActivity")
65+
JavaProxy("com.tns.TestNativeScriptActivity")
6666
], MyActivity);
6767
return MyActivity;
6868
})(android.app.Activity);

test-app/app/src/main/assets/app/MyApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// demonstrates how to extend class in JavaScript with prebuilt Java proxy
2-
var MyApp = android.app.Application.extend("com.tns.NativeScriptApplication",
2+
var MyApp = android.app.Application.extend("com.tns.TestNativeScriptApplication",
33
{
44
onCreate: function()
55
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* AUTO-GENERATED FILE. DO NOT MODIFY.
2+
* This class was automatically generated by the
3+
* static binding generator from the resources it found.
4+
* Please do not modify by hand.
5+
*/
6+
package com.tns;
7+
8+
@com.tns.JavaScriptImplementation(javaScriptFile = "./MyActivity.js")
9+
public class TestNativeScriptActivity extends android.app.Activity
10+
implements com.tns.NativeScriptHashCodeProvider {
11+
public TestNativeScriptActivity() {
12+
super();
13+
com.tns.Runtime.initInstance(this);
14+
}
15+
16+
protected void onCreate(android.os.Bundle param_0) {
17+
java.lang.Object[] args = new java.lang.Object[1];
18+
args[0] = param_0;
19+
com.tns.Runtime.callJSMethod(this, "onCreate", void.class, args);
20+
}
21+
22+
public void onCreate(android.os.Bundle param_0, android.os.PersistableBundle param_1) {
23+
java.lang.Object[] args = new java.lang.Object[2];
24+
args[0] = param_0;
25+
args[1] = param_1;
26+
com.tns.Runtime.callJSMethod(this, "onCreate", void.class, args);
27+
}
28+
29+
public int hashCode__super() {
30+
return super.hashCode();
31+
}
32+
33+
public boolean equals__super(java.lang.Object other) {
34+
return super.equals(other);
35+
}
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* AUTO-GENERATED FILE. DO NOT MODIFY.
2+
* This class was automatically generated by the
3+
* static binding generator from the resources it found.
4+
* Please do not modify by hand.
5+
*/
6+
package com.tns;
7+
8+
@com.tns.JavaScriptImplementation(javaScriptFile = "./MyApp.js")
9+
public class TestNativeScriptApplication extends android.app.Application
10+
implements com.tns.NativeScriptHashCodeProvider {
11+
private static android.app.Application thiz;
12+
13+
public TestNativeScriptApplication() {
14+
super();
15+
thiz = this;
16+
}
17+
18+
public void onCreate() {
19+
com.tns.Runtime runtime = com.tns.RuntimeHelper.initRuntime(this);
20+
if (!com.tns.Runtime.isInitialized()) {
21+
try {
22+
super.onCreate();
23+
return;
24+
} catch (Throwable throwable) {
25+
throw new RuntimeException(throwable);
26+
}
27+
}
28+
java.lang.Object[] args = new java.lang.Object[0];
29+
com.tns.Runtime.callJSMethod(this, "onCreate", void.class, args);
30+
if (runtime != null) {
31+
runtime.run();
32+
}
33+
}
34+
35+
public static android.app.Application getInstance() {
36+
return thiz;
37+
}
38+
39+
public int hashCode__super() {
40+
return super.hashCode();
41+
}
42+
43+
public boolean equals__super(java.lang.Object other) {
44+
return super.equals(other);
45+
}
46+
}

test-app/app/src/main/java/com/tns/tests/StringConversionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void callback(String str) {
7171
private String readString() throws Exception {
7272
String str = null;
7373

74-
Context context = com.tns.NativeScriptApplication.getInstance();
74+
Context context = com.tns.TestNativeScriptApplication.getInstance();
7575

7676
InputStream inputStream = null;
7777
try {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)