के साथ .so फाइलें उत्पन्न करना मैं चलने के माध्यम से here के अनुसार निर्मित एक बहुत ही सरल एनडीकेएस नमूना आवेदन करने पर काम कर रहा हूं। मेरी समस्या यह है कि, मैं .so फ़ाइलों को उत्पन्न करने के लिए एंड्रॉइड स्टूडियो नहीं प्राप्त कर सकता, इसलिए मेरे पास कोई पुस्तकालय नहीं है।एंड्रॉइड स्टूडियो 1.0.2 में एनडीके
मैं समझता हूं कि एनडीके समर्थन अब हटा दिया गया है और इस साल की शुरुआत में एक विकल्प उपलब्ध कराया जाएगा, हालांकि वर्तमान में इस सुविधा का उपयोग करने से मुझे सक्रिय रूप से रोक नहीं रहा है। जब मैं अपने प्रोजेक्ट का निर्माण, मैं निम्नलिखित चेतावनी (नहीं एक त्रुटि) दिया हूँ:
WARNING [Project: :app] Current NDK support is deprecated. Alternative will be provided in the future.
मेरे परियोजना बनाता है, लेकिन जब मैं .apk यह दुर्घटनाओं (उम्मीद के रूप में) के रूप में यह नहीं कर सकते पुस्तकालयों को खोजने/चलाते हैं। तो फाइलें। उदाहरण के अनुसार, परियोजना के निर्माण के दौरान हम इन्हें उत्पन्न होने की उम्मीद करेंगे, क्या यह सही है? यहाँ त्रुटि है:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.ndksample-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libMyLib.so"
मेरी पर्यावरण के बारे में
विंडोज 7, एंड्रॉयड स्टूडियो 1.0.2, एशियाई विकास बैंक नेक्सस 5 चल रहा है (एमुलेटर-5554)
मेरे कोड
उदाहरण के अनुसार:
मुख्य अधिनियम ivity.java
package com.example.ndksample;
//import android.support.v7.app.ActionBarActivity;
// This line is not needed as we are not targetting older devices
import android.app.Activity; //Import this app package to use onCreate etc.
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MainActivity extends Activity {
static{
System.loadLibrary("MyLib");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.my_textview);
tv.setText(getStringFromNative());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public native String getStringFromNative();
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:id="@+id/my_textview"
android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
main.c
#include "com_example_ndksample_MainActivity.h"
/* Header for class com_example_ndksample_MainActivity */
JNIEXPORT jstring JNICALL Java_com_example_ndksample_app_MainActivity_getStringFromNative
(JNIEnv * env, jobject obj)
{
return (*env)->NewStringUTF(env, "Hello from Kyle");
}
build.gradle ध्यान दें: एप्लिकेशन
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.ndksample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
moduleName "MyLib"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
local.properties
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=D\:\\Programs\\Android\\Android SDK
ndk.dir=D\:\\Programs\\Android\\Android NDK
मेरे सवालों का अगर कोई कृपया मदद करने में सक्षम है:
अंत में, मैं कैसे बनाऊँ फ़ाइलों .so आवश्यक !! ??
उप सवाल है कि मुख्य सवाल का जवाब देने में मदद मिल सकती है:
मेरे निर्देशिका लेआउट था मेरे JNI dir एप्लिकेशन के तहत (ताकि NDKSample/ऐप्स/JNI), यह सही है? मुझे here को मानक जेनी निर्देशिका में सी फाइलों को रखने की सलाह नहीं दी गई थी। मैंने इसका परीक्षण किया, और परियोजना के निर्माण पर, यह दुर्घटनाग्रस्त हो गया। त्रुटि:
* विफलता: अपवाद के साथ निर्माण विफल रहा।
- क्या गलत हुआ: निष्पादन कार्य के लिए विफल रहा ': app: compileDebugNdk'।
com.android.ide.common.internal.LoggedErrorException: Failed to run command: D:\Programs\Android\Android NDK\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Kyle\AndroidStudioProjects\NDKSample\app\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-21 NDK_OUT=C:\Users\Kyle\AndroidStudioProjects\NDKSample\app\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\Kyle\AndroidStudioProjects\NDKSample\app\build\intermediates\ndk\debug\lib APP_ABI=all Error Code: 1*
इंटेल से उपरोक्त उदाहरण मुझे निर्देशित नहीं करता है एक Android.mk फ़ाइल का निर्माण करने के लिए, उदाहरण नहीं है और वह एक काम कर आवेदन उत्पन्न करता है। मैंने jni निर्देशिका में एक डालने का परीक्षण किया है, हालांकि इससे मदद नहीं मिली। क्या मुझे एक बनाना चाहिए, और यदि हां, तो मुझे इसे कहां रखना चाहिए
क्या मेरी निर्देशिकाओं की निम्न छवि सही है?
किसी भी मदद की सराहना की जाएगी।
केली
मेरे पास एक ques है मेरे एंड्रॉइड प्रोजेक्ट में फ़ाइलों का उपयोग कैसे करें। क्या आप इसे देख सकते हैं। Http://stackoverflow.com/questions/44929511/specify-so-files-in-build-gradle-file-android-studio –