Skip to content

Commit 9f37f39

Browse files
committed
Merge pull request #150 from NativeScript/revert-144-0-day-fix
Revert "copy the correct android.jar. Correct is the jar pointed by t…
2 parents 4a300d6 + 8fb8aea commit 9f37f39

File tree

2 files changed

+44
-74
lines changed

2 files changed

+44
-74
lines changed

build/project-template/custom_rules.xml

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,43 @@
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>
2734

28-
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" />
35+
36+
<!-- GET MIN SDK VERSION FROM MANIFEST AND SAVE IN PROP "minSdkVersion" -->
37+
<target name="retrieve_min_version_from_manifest">
4438

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-
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>
52+
5653

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+
5764
<target name="copy_project_jars">
5865

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

8087

8188
<!-- PASS JARS TO METADATA GENERATOR -->
82-
<target name="generate_metadata_from_given_jars" depends="create_project_lib, copy_android_jar, copy_project_jars, delete_old_metadata">
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">
8390

8491
<java jar="${ns.resources}/metadata-generator.jar"
8592
fork="true"
@@ -92,7 +99,7 @@
9299

93100
</java>
94101

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

97104
</target>
98105

src/jni/NativeScriptRuntime.cpp

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -197,67 +197,30 @@ void NativeScriptRuntime::CallJavaMethod(const Handle<Object>& caller, const str
197197
if ((entry != nullptr) && entry->isResolved)
198198
{
199199
isStatic = entry->isStatic;
200-
201200
if (entry->memberId == nullptr)
202201
{
203202
entry->clazz = env.FindClass(className);
204203
if (entry->clazz == nullptr)
205204
{
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-
}
205+
DEBUG_WRITE("Cannot resolve class=%s while calling method %s", className.c_str(), methodName.c_str());
232206
}
233-
}
234207

235-
if (entry->clazz != nullptr)
236-
{
237-
clazz = entry->clazz;
238-
mid = reinterpret_cast<jmethodID>(entry->memberId);
208+
entry->memberId = isStatic
209+
? env.GetStaticMethodID(entry->clazz, methodName, entry->sig)
210+
: env.GetMethodID(entry->clazz, methodName, entry->sig);
239211
}
240-
212+
clazz = entry->clazz;
213+
mid = reinterpret_cast<jmethodID>(entry->memberId);
241214
sig = entry->sig;
242215
}
243216
else
244217
{
245-
DEBUG_WRITE("Resolving method: %s.%s on className %s", className.c_str(), methodName.c_str(), className.c_str());
246218
auto mi = MethodCache::ResolveMethodSignature(className, methodName, args, isStatic);
247219
if (mi.mid == nullptr)
248220
{
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-
}
221+
DEBUG_WRITE("Cannot resolve class=%s, method=%s, isStatic=%d, isSuper=%d", className.c_str(), methodName.c_str(), isStatic, isSuper);
222+
return;
259223
}
260-
261224
clazz = mi.clazz;
262225
mid = mi.mid;
263226
sig = mi.signature;

0 commit comments

Comments
 (0)