Skip to content

Commit ff595f8

Browse files
committed
now a basic android NDK project
1 parent 47a1088 commit ff595f8

8 files changed

Lines changed: 173 additions & 4 deletions

File tree

‎android/AndroidManifest.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
android:icon="@drawable/ic_launcher"
1111
android:label="@string/app_name" >
1212
<activity
13-
android:name=".AndroidOpenCVforHackathonsActivity"
13+
android:name="AndroidOpenCVforHackathonsActivity"
1414
android:label="@string/app_name" >
1515
<intent-filter>
1616
<action android:name="android.intent.action.MAIN" />

‎android/jni/Android.mk‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (C) 2009 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
LOCAL_PATH := $(call my-dir)
16+
17+
include $(CLEAR_VARS)
18+
19+
LOCAL_MODULE := hello-jni
20+
LOCAL_SRC_FILES := hello-jni.c
21+
22+
include $(BUILD_SHARED_LIBRARY)

‎android/jni/hello-jni.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2009 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
#include <string.h>
18+
#include <jni.h>
19+
20+
/* This is a trivial JNI example where we use a native method
21+
* to return a new VM String. See the corresponding Java source
22+
* file located at:
23+
*
24+
* apps/samples/hello-jni/project/src/com/example/HelloJni/HelloJni.java
25+
*/
26+
jstring
27+
Java_com_androidmontreal_opencv_AndroidOpenCVforHackathonsActivity_stringFromJNI( JNIEnv* env,
28+
jobject thiz )
29+
{
30+
return (*env)->NewStringUTF(env, "Hello from JNI !");
31+
}

‎android/res/layout/main.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
android:orientation="vertical" >
66

77
<TextView
8+
android:id="@+id/textview1"
89
android:layout_width="fill_parent"
910
android:layout_height="wrap_content"
1011
android:text="@string/hello" />
Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,67 @@
1+
/*
2+
* Copyright (C) 2009 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.androidmontreal.opencv;
217

318
import android.app.Activity;
19+
import android.widget.TextView;
420
import android.os.Bundle;
521

6-
public class AndroidOpenCVforHackathonsActivity extends Activity {
22+
23+
public class AndroidOpenCVforHackathonsActivity extends Activity
24+
{
725
/** Called when the activity is first created. */
826
@Override
9-
public void onCreate(Bundle savedInstanceState) {
27+
public void onCreate(Bundle savedInstanceState)
28+
{
1029
super.onCreate(savedInstanceState);
30+
31+
/* Create a TextView and set its content.
32+
* the text is retrieved by calling a native
33+
* function.
34+
*/
1135
setContentView(R.layout.main);
36+
TextView tv = (TextView) findViewById(R.id.textview1);
37+
tv.setText( stringFromJNI() );
38+
39+
}
40+
41+
/* A native method that is implemented by the
42+
* 'hello-jni' native library, which is packaged
43+
* with this application.
44+
*/
45+
public native String stringFromJNI();
46+
47+
/* This is another native method declaration that is *not*
48+
* implemented by 'hello-jni'. This is simply to show that
49+
* you can declare as many native methods in your Java code
50+
* as you want, their implementation is searched in the
51+
* currently loaded native libraries only the first time
52+
* you call them.
53+
*
54+
* Trying to call this function will result in a
55+
* java.lang.UnsatisfiedLinkError exception !
56+
*/
57+
public native String unimplementedStringFromJNI();
58+
59+
/* this is used to load the 'hello-jni' library on application
60+
* startup. The library has already been unpacked into
61+
* /data/data/com.example.HelloJni/lib/libhello-jni.so at
62+
* installation time by the package manager.
63+
*/
64+
static {
65+
System.loadLibrary("hello-jni");
1266
}
13-
}
67+
}

‎eclipseconfig/.classpathsample‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry kind="output" path="bin/classes"/>
8+
</classpath>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
3+
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;resources&gt;&#10;&lt;item path=&quot;/HelloJni/lib&quot; type=&quot;2&quot;/&gt;&#10;&lt;/resources&gt;}"/>
4+
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
5+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;resources&gt;&#10;&lt;item path=&quot;/HelloJni/jni&quot; type=&quot;2&quot;/&gt;&#10;&lt;/resources&gt;}"/>
6+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="/Users/gina/android/android-ndk-r7/ndk-build"/>
7+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
8+
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
9+
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/AndroidOpenCVforHackathons}"/>
10+
</launchConfiguration>

‎eclipseconfig/.projectsample‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>AndroidOpenCVforHackathons</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
<buildCommand>
29+
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
30+
<triggers>auto,full,incremental,</triggers>
31+
<arguments>
32+
<dictionary>
33+
<key>LaunchConfigHandle</key>
34+
<value>&lt;project&gt;/.externalToolBuilders/AndroidOpenCVforHackathonsBuilder.launch</value>
35+
</dictionary>
36+
</arguments>
37+
</buildCommand>
38+
</buildSpec>
39+
<natures>
40+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
41+
<nature>org.eclipse.jdt.core.javanature</nature>
42+
</natures>
43+
</projectDescription>

0 commit comments

Comments
 (0)