Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 29 additions & 36 deletions build/project-template/custom_rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,36 @@
<mkdir dir="${ns.project.lib}"/>

</target>


<target name="copy_default_sdk" >

<copy file="${ns.resources}/android.jar" todir="${ns.project.lib}"/>

</target>


<!-- GET MIN SDK VERSION FROM MANIFEST AND SAVE IN PROP "minSdkVersion" -->
<target name="retrieve_min_version_from_manifest">

<xmlproperty file="./AndroidManifest.xml" collapseAttributes="true"/>

<property name="relative_path_to_min_declared_sdk" value="platforms/android-${manifest.uses-sdk.android:minSdkVersion}/android.jar" />

</target>


<!-- DOES MIN SDK EXIST, AS DECLARED IN MANIFEST? -->
<target name="does_min_sdk_jar_exist" depends="retrieve_min_version_from_manifest">

<available file="${sdk.dir}/${relative_path_to_min_declared_sdk}" property="minSdkJar.present"/>

</target>

<!-- jar file from where the tasks are loaded -->
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/ant-tasks.jar" />
</path>

<!-- Custom tasks -->
<taskdef resource="anttasks.properties" classpathref="android.antlibs" />

<echo level="info">Resolving Android.jar and Build Target for ${ant.project.name}...</echo>
<gettarget
androidJarFileOut="project.target.android.jar"
androidAidlFileOut="project.target.framework.aidl"
bootClassPathOut="project.target.class.path"
targetApiOut="project.target.apilevel"
minSdkVersionOut="project.minSdkVersion" />

<condition property="android.jar.present" value="${project.target.android.jar}">
<isset property="project.target.android.jar" />
</condition>
<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" />

<echo level="info">Using android.jar from ${project.target.android.jar}</echo>

<target name="copy_android_jar">
<copy file="${project.target.android.jar}" todir="${ns.project.lib}" preservelastmodified="true"/>
</target>


<!-- REPLACE MIN SDK JAR WITH ONE ON USER MACHINE -->
<target name="replace_default_sdk_if_possible" depends="does_min_sdk_jar_exist" if="minSdkJar.present">

<delete file="${ns.project.lib}/android.jar"/>

<copy file="${sdk.dir}/${relative_path_to_min_declared_sdk}" todir="${ns.project.lib}"/>

</target>


<target name="copy_project_jars">

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


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

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

</java>

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

</target>

Expand Down
53 changes: 45 additions & 8 deletions src/jni/NativeScriptRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,67 @@ void NativeScriptRuntime::CallJavaMethod(const Handle<Object>& caller, const str
if ((entry != nullptr) && entry->isResolved)
{
isStatic = entry->isStatic;

if (entry->memberId == nullptr)
{
entry->clazz = env.FindClass(className);
if (entry->clazz == nullptr)
{
DEBUG_WRITE("Cannot resolve class=%s while calling method %s", className.c_str(), methodName.c_str());
MetadataNode* callerNode = MetadataNode::GetNodeFromHandle(caller);
const string callerClassName = callerNode->GetName();

DEBUG_WRITE("Cannot resolve class: %s while calling method: %s callerClassName: %s", className.c_str(), methodName.c_str(), callerClassName.c_str());
clazz = env.FindClass(callerClassName);
if (clazz == nullptr)
{
ASSERT_FAIL("Cannot resolve caller's class name: %s", callerClassName.c_str());
return;
}

mid = isStatic ?
env.GetStaticMethodID(clazz, methodName, entry->sig) :
env.GetMethodID(clazz, methodName, entry->sig);
}
else
{
entry->memberId = isStatic ?
env.GetStaticMethodID(entry->clazz, methodName, entry->sig) :
env.GetMethodID(entry->clazz, methodName, entry->sig);

if (entry->memberId == nullptr)
{
ASSERT_FAIL("Cannot resolve a method %s on class: %s", methodName.c_str(), className.c_str());
return;
}
}
}

entry->memberId = isStatic
? env.GetStaticMethodID(entry->clazz, methodName, entry->sig)
: env.GetMethodID(entry->clazz, methodName, entry->sig);
if (entry->clazz != nullptr)
{
clazz = entry->clazz;
mid = reinterpret_cast<jmethodID>(entry->memberId);
}
clazz = entry->clazz;
mid = reinterpret_cast<jmethodID>(entry->memberId);

sig = entry->sig;
}
else
{
DEBUG_WRITE("Resolving method: %s.%s on className %s", className.c_str(), methodName.c_str(), className.c_str());
auto mi = MethodCache::ResolveMethodSignature(className, methodName, args, isStatic);
if (mi.mid == nullptr)
{
DEBUG_WRITE("Cannot resolve class=%s, method=%s, isStatic=%d, isSuper=%d", className.c_str(), methodName.c_str(), isStatic, isSuper);
return;
MetadataNode* callerNode = MetadataNode::GetNodeFromHandle(caller);
const string callerClassName = callerNode->GetName();
DEBUG_WRITE("Resolving method on callers class: %s.%s on className %s", callerClassName.c_str(), methodName.c_str(), className.c_str());
mi = MethodCache::ResolveMethodSignature(callerClassName, methodName, args, isStatic);
if (mi.mid == nullptr)
{
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());
APP_FAIL("Cannot resolve class");
return;
}
}

clazz = mi.clazz;
mid = mi.mid;
sig = mi.signature;
Expand Down