Skip to content

Commit 4a300d6

Browse files
committed
Merge pull request #144 from NativeScript/0-day-fix
copy the correct android.jar. Correct is the jar pointed by the targe…
2 parents 6fc2774 + e507d75 commit 4a300d6

File tree

2 files changed

+74
-44
lines changed

2 files changed

+74
-44
lines changed

build/project-template/custom_rules.xml

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,36 @@
2424
<mkdir dir="${ns.project.lib}"/>
2525

2626
</target>
27-
28-
29-
<target name="copy_default_sdk" >
30-
31-
<copy file="${ns.resources}/android.jar" todir="${ns.project.lib}"/>
32-
33-
</target>
3427

35-
36-
<!-- GET MIN SDK VERSION FROM MANIFEST AND SAVE IN PROP "minSdkVersion" -->
37-
<target name="retrieve_min_version_from_manifest">
38-
39-
<xmlproperty file="./AndroidManifest.xml" collapseAttributes="true"/>
40-
41-
<property name="relative_path_to_min_declared_sdk" value="platforms/android-${manifest.uses-sdk.android:minSdkVersion}/android.jar" />
42-
43-
</target>
44-
45-
46-
<!-- DOES MIN SDK EXIST, AS DECLARED IN MANIFEST? -->
47-
<target name="does_min_sdk_jar_exist" depends="retrieve_min_version_from_manifest">
48-
49-
<available file="${sdk.dir}/${relative_path_to_min_declared_sdk}" property="minSdkJar.present"/>
50-
51-
</target>
5228

29+
<!-- jar file from where the tasks are loaded -->
30+
<path id="android.antlibs">
31+
<pathelement path="${sdk.dir}/tools/lib/ant-tasks.jar" />
32+
</path>
33+
34+
<!-- Custom tasks -->
35+
<taskdef resource="anttasks.properties" classpathref="android.antlibs" />
36+
37+
<echo level="info">Resolving Android.jar and Build Target for ${ant.project.name}...</echo>
38+
<gettarget
39+
androidJarFileOut="project.target.android.jar"
40+
androidAidlFileOut="project.target.framework.aidl"
41+
bootClassPathOut="project.target.class.path"
42+
targetApiOut="project.target.apilevel"
43+
minSdkVersionOut="project.minSdkVersion" />
44+
45+
<condition property="android.jar.present" value="${project.target.android.jar}">
46+
<isset property="project.target.android.jar" />
47+
</condition>
48+
<fail unless="android.jar.present" message="android.jar is not set. Setup the sdk directory for this project or update project.properties with the correct target version" />
49+
50+
<echo level="info">Using android.jar from ${project.target.android.jar}</echo>
51+
52+
<target name="copy_android_jar">
53+
<copy file="${project.target.android.jar}" todir="${ns.project.lib}" preservelastmodified="true"/>
54+
</target>
55+
5356

54-
<!-- REPLACE MIN SDK JAR WITH ONE ON USER MACHINE -->
55-
<target name="replace_default_sdk_if_possible" depends="does_min_sdk_jar_exist" if="minSdkJar.present">
56-
57-
<delete file="${ns.project.lib}/android.jar"/>
58-
59-
<copy file="${sdk.dir}/${relative_path_to_min_declared_sdk}" todir="${ns.project.lib}"/>
60-
61-
</target>
62-
63-
6457
<target name="copy_project_jars">
6558

6659
<copy todir="${ns.project.lib}" verbose="yes" flatten="yes" failonerror="no">
@@ -86,7 +79,7 @@
8679

8780

8881
<!-- PASS JARS TO METADATA GENERATOR -->
89-
<target name="generate_metadata_from_given_jars" depends="create_project_lib, copy_default_sdk, replace_default_sdk_if_possible, copy_project_jars, delete_old_metadata">
82+
<target name="generate_metadata_from_given_jars" depends="create_project_lib, copy_android_jar, copy_project_jars, delete_old_metadata">
9083

9184
<java jar="${ns.resources}/metadata-generator.jar"
9285
fork="true"
@@ -99,7 +92,7 @@
9992

10093
</java>
10194

102-
<echo message=" --------- created new metadata and moved it to assets/metadata" />
95+
<echo message="Created new metadata and moved it to assets/metadata" />
10396

10497
</target>
10598

src/jni/NativeScriptRuntime.cpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,30 +197,67 @@ void NativeScriptRuntime::CallJavaMethod(const Handle<Object>& caller, const str
197197
if ((entry != nullptr) && entry->isResolved)
198198
{
199199
isStatic = entry->isStatic;
200+
200201
if (entry->memberId == nullptr)
201202
{
202203
entry->clazz = env.FindClass(className);
203204
if (entry->clazz == nullptr)
204205
{
205-
DEBUG_WRITE("Cannot resolve class=%s while calling method %s", className.c_str(), methodName.c_str());
206+
MetadataNode* callerNode = MetadataNode::GetNodeFromHandle(caller);
207+
const string callerClassName = callerNode->GetName();
208+
209+
DEBUG_WRITE("Cannot resolve class: %s while calling method: %s callerClassName: %s", className.c_str(), methodName.c_str(), callerClassName.c_str());
210+
clazz = env.FindClass(callerClassName);
211+
if (clazz == nullptr)
212+
{
213+
ASSERT_FAIL("Cannot resolve caller's class name: %s", callerClassName.c_str());
214+
return;
215+
}
216+
217+
mid = isStatic ?
218+
env.GetStaticMethodID(clazz, methodName, entry->sig) :
219+
env.GetMethodID(clazz, methodName, entry->sig);
220+
}
221+
else
222+
{
223+
entry->memberId = isStatic ?
224+
env.GetStaticMethodID(entry->clazz, methodName, entry->sig) :
225+
env.GetMethodID(entry->clazz, methodName, entry->sig);
226+
227+
if (entry->memberId == nullptr)
228+
{
229+
ASSERT_FAIL("Cannot resolve a method %s on class: %s", methodName.c_str(), className.c_str());
230+
return;
231+
}
206232
}
233+
}
207234

208-
entry->memberId = isStatic
209-
? env.GetStaticMethodID(entry->clazz, methodName, entry->sig)
210-
: env.GetMethodID(entry->clazz, methodName, entry->sig);
235+
if (entry->clazz != nullptr)
236+
{
237+
clazz = entry->clazz;
238+
mid = reinterpret_cast<jmethodID>(entry->memberId);
211239
}
212-
clazz = entry->clazz;
213-
mid = reinterpret_cast<jmethodID>(entry->memberId);
240+
214241
sig = entry->sig;
215242
}
216243
else
217244
{
245+
DEBUG_WRITE("Resolving method: %s.%s on className %s", className.c_str(), methodName.c_str(), className.c_str());
218246
auto mi = MethodCache::ResolveMethodSignature(className, methodName, args, isStatic);
219247
if (mi.mid == nullptr)
220248
{
221-
DEBUG_WRITE("Cannot resolve class=%s, method=%s, isStatic=%d, isSuper=%d", className.c_str(), methodName.c_str(), isStatic, isSuper);
222-
return;
249+
MetadataNode* callerNode = MetadataNode::GetNodeFromHandle(caller);
250+
const string callerClassName = callerNode->GetName();
251+
DEBUG_WRITE("Resolving method on callers class: %s.%s on className %s", callerClassName.c_str(), methodName.c_str(), className.c_str());
252+
mi = MethodCache::ResolveMethodSignature(callerClassName, methodName, args, isStatic);
253+
if (mi.mid == nullptr)
254+
{
255+
ASSERT_FAIL("Cannot resolve class=%s, method=%s, isStatic=%d, isSuper=%d, callerClass=%s", className.c_str(), methodName.c_str(), isStatic, isSuper, callerClassName.c_str());
256+
APP_FAIL("Cannot resolve class");
257+
return;
258+
}
223259
}
260+
224261
clazz = mi.clazz;
225262
mid = mi.mid;
226263
sig = mi.signature;

0 commit comments

Comments
 (0)