Differences

This shows you the differences between two versions of the page.

Link to this comparison view

osp:lectures:lecture-ndk [2016/11/07 00:04]
vlad.traista [Practical]
osp:lectures:lecture-ndk [2017/01/22 11:38] (current)
laura.ruse [Lecture]
Line 8: Line 8:
  
  
-  *{{:​osp:​lectures:​lecture-ndk.pdf | Lecture ​Slides - Part 1}}+  *{{:​osp:​lectures:​lecture-ndk.pdf | Slides ​- Part 1}} 
 +  *{{:​osp:​lectures:​6.ndk_notes.pdf | Notes - Part 1}}
  
 {{url>​http://​ocw.cs.pub.ro/​courses/​_media/​osp/​lectures/​lecture-ndk.pdf}} {{url>​http://​ocw.cs.pub.ro/​courses/​_media/​osp/​lectures/​lecture-ndk.pdf}}
  
-  *{{:​osp:​lectures:​lecture-ndk-2.pdf | Lecture ​Slides - Part 2}}+  *{{:​osp:​lectures:​lecture-ndk-2.pdf | Slides ​- Part 2}} 
 +  *{{:​osp:​lectures:​6.ndk2_notes.pdf | Notes - Part 2}}
  
 {{url>​http://​ocw.cs.pub.ro/​courses/​_media/​osp/​lectures/​lecture-ndk-2.pdf}} {{url>​http://​ocw.cs.pub.ro/​courses/​_media/​osp/​lectures/​lecture-ndk-2.pdf}}
Line 26: Line 28:
  
 <note warning>​If you do not have the Android NDK installed, you can downloand it and extract it from [[https://​developer.android.com/​ndk/​downloads/​index.html|this link]]. Afterwards in Android Studio you must set the NDK path if it is not set already. The path can be set by right clicking on the project and selecting the **Open Module Settings** menu item and setting the Android NDK location with a path similar to **/​home/​student/​android-ndk-10re**. <note warning>​If you do not have the Android NDK installed, you can downloand it and extract it from [[https://​developer.android.com/​ndk/​downloads/​index.html|this link]]. Afterwards in Android Studio you must set the NDK path if it is not set already. The path can be set by right clicking on the project and selecting the **Open Module Settings** menu item and setting the Android NDK location with a path similar to **/​home/​student/​android-ndk-10re**.
 +</​note>​
 +
 +<note warning>
 +In order to successfully run an Android application with native support, you need to have [[http://​www.oracle.com/​technetwork/​java/​javase/​downloads/​jdk7-downloads-1880260.html|Oracle Java 7 SDK]] installed and configure Android Studio to use that SDK.
 </​note>​ </​note>​
  
 === Files === === Files ===
  
-{{:​osp:​lectures:​nativeapplication.zip|}}+{{:​osp:​lectures:​introapplication.zip|}}
 {{:​osp:​lectures:​tasks.zip|}} {{:​osp:​lectures:​tasks.zip|}}
  
 +<note warning>
 +Abandon hope all ye who enter here for Android NDK is a mighty obstacle :D
 +</​note>​
  
-TODO - needs refactoring 
 === Task 1 - Create a Native Project (1p) === === Task 1 - Create a Native Project (1p) ===
  
-<note warning>​Because NDK is not fully support on Android Studio yet, you will have to import the project from this archive: {{:​osp:​lectures:​nativeapplication.zip|}}+<note warning>​Because NDK is not fully support on Android Studio yet, you will have to import the project from this archive: {{:​osp:​lectures:​introapplication.zip|}}
 You should use this whenever a new project is required. You can find more information about NDK integration in Android Studio at [[http://​tools.android.com/​tech-docs/​new-build-system/​gradle-experimental|this link]]. You should use this whenever a new project is required. You can find more information about NDK integration in Android Studio at [[http://​tools.android.com/​tech-docs/​new-build-system/​gradle-experimental|this link]].
 </​note>​ </​note>​
  
-Create a new project. +Edit native.cpp and add the following function:
- +
-Edit native.and add the following function:+
 <code C++> <code C++>
 extern "​C"​ extern "​C"​
 jstring Java_com_example_user_nativeapplication_MainActivity_getString(JNIEnv *env, jobject instance) jstring Java_com_example_user_nativeapplication_MainActivity_getString(JNIEnv *env, jobject instance)
 { {
- return env->​NewStringUTF(env, "Hello world from JNI!"​);​+ return env->​NewStringUTF("​Hello world from JNI!"​);​
 } }
 </​code>​ </​code>​
Line 77: Line 83:
 === Task 2 - Logging from Native Code (1p) === === Task 2 - Logging from Native Code (1p) ===
  
-To use logging from native code you will have to include **<​android/​log.h>​**. Add this include to **native.c**. You will have to also link this module against liblog. This already done in the imported project (ldLibs += "​log"​ in gradle.build).+To use logging from native code you will have to include **<​android/​log.h>​**. Add this include to **native-lib.cpp**. You will have to also link this module against liblog. This already done in the imported project (ldLibs += "​log"​ in gradle.build).
  
 Then, to print something, you need to use this macro: Then, to print something, you need to use this macro:
osp/lectures/lecture-ndk.1478469890.txt.gz · Last modified: 2016/11/07 00:04 by vlad.traista
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0