Trying to build an Android UI element in a library - java

I've spent the last two hours trying to figure out how to do this, and am coming up blank. I've looked through many of the entries here on stackoverflow related to this...although I've tried to follow the fixes as written nothing has helped. I think if I had a better understanding of how Java, Android, and Eclipse worked I could use the previous answers, but I'm going to need a more basic explanation. Here's what I'm trying to do: I've created an Android Library Project called AndroidUILibrary. I can't post the image of what my Java Build Path window looks like (need 10 reputation points), but I am exporting both the src and gen folders from my project.
In this library project I have the following class:
public class FileDialogFragment extends DialogFragment {
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
activity = getActivity();
activity.setContentView(R.id.fileDialogFragmentLinearLayout);
and the library's manifest looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sailbravado.androiduilibrary"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<library />
<application
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</application>
</manifest>
In my Android Application I have the following code:
final FileDialogFragment fileDialog = new FileDialogFragment();
fileDialog.setCanSelectFiles(false);
fileDialog.setOnClickListener(new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
logFolderValueTextView.setText(fileDialog.getSelectedFiles().get(0).getAbsolutePath());
logFolderValueTextView.setTag(true);
}
}
});
fileDialog.show(activity.getFragmentManager(), "");
In my Android application's Java Build Path I added AndroidUILibrary to the Projects tab, androiduilibrary.jar to the Libraries tab, and ensured that all entries are checked in Order and Export. I then attempt to run the application. The Console shows the following output:
[2014-09-20 18:45:03 - GPSLogger] Dx
trouble writing output: already prepared
[2014-09-20 18:45:04 - GPSLogger] ------------------------------
[2014-09-20 18:45:04 - GPSLogger] Android Launch!
[2014-09-20 18:45:04 - GPSLogger] adb is running normally.
[2014-09-20 18:45:04 - GPSLogger] Performing com.sailbravado.gpslogger.GPSLoggerActivity activity launch
[2014-09-20 18:45:04 - GPSLogger] Automatic Target Mode: using device 'E5ATCT027686'
[2014-09-20 18:45:04 - GPSLogger] Uploading GPSLogger.apk onto device 'E5ATCT027686'
[2014-09-20 18:45:04 - GPSLogger] Installing GPSLogger.apk...
[2014-09-20 18:45:07 - GPSLogger] Success!
[2014-09-20 18:45:07 - AndroidUILibrary] Could not find AndroidUILibrary.apk!
[2014-09-20 18:45:07 - GPSLogger] Starting activity com.sailbravado.gpslogger.GPSLoggerActivity on device E5ATCT027686
[2014-09-20 18:45:08 - GPSLogger] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.sailbravado.gpslogger/.GPSLoggerActivity }
When the "Dx" entry in the Console shows up, I notice a new folder gets created in my project hierarchy: bin/dexedLibs. It contains two JAR files...my androiduilibrary and appcompat_v7, both followed by a 32-digit hex number. The application launches fine, but when I invoke the part that should create the dialog, I get:
09-20 18:53:58.355: E/AndroidRuntime(2739): FATAL EXCEPTION: main
09-20 18:53:58.355: E/AndroidRuntime(2739): Process: com.sailbravado.gpslogger, PID: 2739
09-20 18:53:58.355: E/AndroidRuntime(2739): java.lang.NoClassDefFoundError: com.sailbravado.androiduilibrary.R$id
09-20 18:53:58.355: E/AndroidRuntime(2739): at com.sailbravado.androiduilibrary.FileDialogFragment.onCreateDialog(FileDialogFragment.java:251)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.app.DialogFragment.getLayoutInflater(DialogFragment.java:398)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.app.BackStackRecord.run(BackStackRecord.java:685)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.os.Handler.handleCallback(Handler.java:733)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.os.Handler.dispatchMessage(Handler.java:95)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.os.Looper.loop(Looper.java:136)
09-20 18:53:58.355: E/AndroidRuntime(2739): at android.app.ActivityThread.main(ActivityThread.java:5072)
09-20 18:53:58.355: E/AndroidRuntime(2739): at java.lang.reflect.Method.invokeNative(Native Method)
09-20 18:53:58.355: E/AndroidRuntime(2739): at java.lang.reflect.Method.invoke(Method.java:515)
09-20 18:53:58.355: E/AndroidRuntime(2739): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-20 18:53:58.355: E/AndroidRuntime(2739): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-20 18:53:58.355: E/AndroidRuntime(2739): at dalvik.system.NativeStart.main(Native Method)
Opening in the debugger, the exception is being thrown from the setContentView() call in the library code.
I tried adding a uses-library tag in the application's manifest, but I get:
[2014-09-20 18:02:51 - GPSLogger] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2014-09-20 18:02:51 - GPSLogger] Please check logcat output for more details.
[2014-09-20 18:02:51 - GPSLogger] Launch canceled!
Thanks in advance for any advice.

Related

ANDROID STUDIO builds succesfully but doesn't run

I've just built my first android app copying the code from this video: https://www.youtube.com/watch?v=gTy13ioTddg&t=594s
The app builds without problems but when I try to run it, it suddenly closes.
That's the message of the debugger:
12/02 12:19:56: Launching 'app' on Pixel_3a_API_30_x86.
Install successfully finished in 519 ms.
$ adb shell am start -n "com.example.pokedex/com.example.pokedex.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.pokedex | com.example.pokedex.test
Waiting for application to come online: com.example.pokedex | com.example.pokedex.test
Connecting to com.example.pokedex
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.pokedex is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:52033', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/chatty: uid=10153(com.example.pokedex) identical 2 lines
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1475)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/example.pokede: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/example.pokede: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pokedex, PID: 8349
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pokedex/com.example.pokedex.MainActivity}: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: android.support.constraint.ConstraintLayout
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.view.LayoutInflater.createView(LayoutInflater.java:813)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.inflate(LayoutInflater.java:657)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.pokedex.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/~~ikbXqJo2xtaJUvZzC7gM8Q==/com.example.pokedex-kRHbfAkGOaaI21CGLAjxuQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~ikbXqJo2xtaJUvZzC7gM8Q==/com.example.pokedex-kRHbfAkGOaaI21CGLAjxuQ==/lib/x86, /system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 26 more
I/Process: Sending signal. PID: 8349 SIG: 9
Disconnected from the target VM, address: 'localhost:52033', transport: 'socket'
This is my Main Activity:
package com.example.pokedex;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private RecyclerView.LayoutManager layoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=findViewById(R.id.recycler_view);
adapter=new PokedexAdapter();
layoutManager=new LinearLayoutManager(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(layoutManager);
}
}
Activity main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycler_view"/>
</android.support.constraint.ConstraintLayout>
Pokedex_row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pokedex_row">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pokedex_row_text_view"/>
</LinearLayout>
Android Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pokedex">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Pokedex">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I've been trying to solve this problem several days so I would be very thankful if someone can help me!
Have tried you changing your ConstraintLayout to use androidx instead of support
try changing the opening tag of activity_main.xml to be:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
and corresponding closing tag to be
</androidx.constraintlayout.widget.ConstraintLayout>
and then sync your project while connected to the internet.
I think it has problem with ConstraintLayout, can you share your xml files, that way I can help you batter.
I experience this error from time to time and use to solve by doing the following:
First, check if you have ConstraintLayout implementation in your app Gradle config
Then make sure there is no Error(maybe a semantic one) in your layout XML file
If the error persists, consider adding those two files to your question description so that one can easily help
Good Luck!

Android App Crashes on Real Device If apk is manually installed

My Application is running fine in Emulators and even in real devices installed by android studio for debugging purpose, but it is crashing if installed manually using apk file.
I am ready to paste any other codes, like Activity if required.
Here is the logcat:
04-14 12:20:44.392 6220-6220/? I/art: Late-enabling -Xcheck:jni
04-14 12:20:44.465 6220-6220/test.planner W/System: ClassLoader referenced unknown path: /data/app/test.planner-1/lib/arm
04-14 12:20:44.467 6220-6220/test.planner I/InstantRun: starting instant run server: is main process
04-14 12:20:44.470 6220-6220/test.planner D/AndroidRuntime: Shutting down VM
04-14 12:20:44.471 6220-6220/test.planner E/AndroidRuntime: FATAL EXCEPTION: main
Process: test.planner, PID: 6220
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{test.planner/test.planner.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "test.planner.MainActivity" on path: DexPathList[[zip file "/data/app/test.planner-1/base.apk"],nativeLibraryDirectories=[/data/app/test.planner-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "test.planner.MainActivity" on path: DexPathList[[zip file "/data/app/test.planner-1/base.apk"],nativeLibraryDirectories=[/data/app/test.planner-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Suppressed: java.lang.ClassNotFoundException: test.planner.MainActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Just go to:
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
and disable instant run.
If you just upgraded your android studio.
You will not have this option to disable -> Instant Run. (not on the menu)
Seems like with new android studio and gradle upgrade in order to install an apk you need to properly build it.
Option 1: with gradle from command line
./gradlew :appName:clean
./gradlew :appName:build
Option 2: from android studio
Android Studio -> build -> build APK (or generate sighed APK)
The generated apk can be installed fine on a device.
Note: if you start a new applicate with this version of android studio you will see that when you run from studio there is no apk generated anymore.
I faced the similar problem.
Note the size of Apk, it would be very small in size , this is because of the instant run feature in enabled. Just disable it
May be Android Studio is not including all files in Apk, when we use the instant run to fasten the process.
Any body know why this happening?
Go to :
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
and disable instant run.

ApplicationClass ClassNotFoundException

I'm using the application class , so I had to create the manifest file, as follows:
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
I have to work normally without problems when testing , often the error occurred in the Google Play Store error report.
But the error report is posted on the Android version 4.4 , I even tested at 4.4 operate normally.
If the person experiencing this problem help me.
java.lang.RuntimeException: Unable to instantiate application com.moonae.android.common.ApplicationClass: java.lang.ClassNotFoundException: Didn't find class "com.culturelandnew.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4524)
at android.app.ActivityThread.access$1500(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.moonae.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:993)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
is this a typo? i have not seen this before i mean android.name to android:name..btw
quick suggestion, remove your application tag, and use the eclipse gui side to search the application class and reference it.. mostly it references the it without package name included.. like this.. =>
<application
android:name="ApplicationClass"
android:icon="#drawble/ic_launcher"
android:largeHeap="true"
....>

Vitamio Sample Error - java.lang.UnsatisfiedLinkError: Couldn't load vinit findLibrary returned null

I'm having trouble running the vitamio-sample from https://github.com/yixia/VitamioBundle.
I am building it with Android Studio and it compiles fine and runs, but when it gets to this line:
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
It throws an exception when I run it on my Nexus 5 (and also on a Galaxy S4):
01-22 11:58:40.759 12323-12323/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: io.vov.vitamio.demo, PID: 12323
java.lang.UnsatisfiedLinkError: Couldn't load vinit from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/io.vov.vitamio.demo-1.apk"],nativeLibraryDirectories=[/data/app-lib/io.vov.vitamio.demo-1, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at io.vov.vitamio.Vitamio.<clinit>(Vitamio.java:258)
at io.vov.vitamio.LibsChecker.checkVitamioLibs(LibsChecker.java:40)
at io.vov.vitamio.demo.VitamioListActivity.onCreate(VitamioListActivity.java:40)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
The exception also happens when I'm running the v4.2.0 tree in my own app.
Any idea what I'm missing? In my own app I pulled the vitamio project into a libraries folder and am referencing it like this:
compile(project(':libraries:vitamio'))
The sample project is left as-is.
I am not sure if there is a cleaner way in the newer version of Vitamino (or gradle). But here is how I got it to work with gradle build tools 0.6.
Added a project to my /libraries directory with the vitamino source/sdk. This has a /libs/armeabi /libs/armeabi-v7a with libvinit.so inside.
In my build.gradle for my main project, reference the library project like:
dependencies {
// other dependencies
compile(project(':libraries:vitamio'))
}
Add the following to the bottom of my build.gradle
task copyNativeLibs(type: Copy) {
from(new File(project(':libraries:vitamio').getProjectDir(), 'libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniDir new File(buildDir, 'native-libs')
}
Then when i run a clean and rebuild it will copy the native libs to the proper spot and include them in the build.

NullPointerException in Android when declaring a Content Provider

I'm facing a strange issue when declaring a Content Provider in my project. I'm copying the classes and Manifest declaration from another project of my own. It's working OK on my other project.
Here's part of my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.qr"
android:installLocation="auto"
android:versionCode="540"
android:versionName="5.4" >
(...)
<application
android:name=".Application"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/ic_launch" >
(...)
<provider
android:name=".provider.HistoryProvider"
android:authorities="com.example.qr.History"
android:exported="true"
android:multiprocess="true"
android:readPermission="com.example.qr.History.read"
android:writePermission="com.example.qr.History.write" />
(...)
</application>
</manifest>
When I run my app, I get this stack trace:
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.ActivityThread.installProvider(ActivityThread.java:4783)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4430)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4372)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
This is the whole stack trace. No 'com.example' trace is included. Of course some code in my app is producing this but the actual crash happens in Android.
Because my own classes are not included in the stack trace, I really don't know where to look.
I've run the code in an emulator with Android 4.2 and I've compared it with the source code of that version of Android, so I know the crash is produced in this line of ActivityThread:
4782 ApplicationInfo ai = info.applicationInfo;
4783 if (context.getPackageName().equals(ai.packageName)) {
Here's a link to the source code of this class.
If I don't declare the content provider (i.e. if I remove from my Manifest), the app works perfectly.
I've added some logs to my Application class, as well as the main Activity class. The crash is produced before either is launched.
So, my question is: what in my code can be producing context, context.getPackageName() or info.applicationInfo to be null during installation?
EDIT
When triggering the stack trace in the emulator several times, I only get this between traces:
09-11 23:10:21.250: E/AndroidRuntime(933): at dalvik.system.NativeStart.main(Native Method)
09-11 23:10:21.470: D/dalvikvm(933): GC_CONCURRENT freed 142K, 9% free 2951K/3224K, paused 78ms+3ms, total 225ms
09-11 23:10:44.030: I/Process(933): Sending signal. PID: 933 SIG: 9
09-11 23:10:46.940: D/dalvikvm(947): GC_CONCURRENT freed 164K, 10% free 2711K/2996K, paused 13ms+114ms, total 201ms
09-11 23:10:47.170: I/ActivityThread(947): Pub com.example.qr.History: com.example.qr.provider.HistoryProvider
09-11 23:10:47.170: D/AndroidRuntime(947): Shutting down VM
09-11 23:10:47.170: W/dalvikvm(947): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
09-11 23:10:47.180: E/AndroidRuntime(947): FATAL EXCEPTION: main

Categories