I am using https://www.youtube.com/watch?v=kjsC-lKUgM8 tutorial to try to debug a simple NDK app. I have done everything as it is in the video except:
I am on OS X 10.9.3 instead of Windows.
I don't use android:debuggable=true(cause eclipse considers it as error) in AndroidManifest.xml instead I have set the NDK path from Preferences->Android->NDK and in Project Properties -> C/C++ Build unchecked Use default build command and set there ndk-build NDK_DEBUG=1 APP_OPTIM=debug.
I don't use x86 emulator but Samsung Duos S device with Android 4.0.4
But the breakpoiin that is used in the video in not being hit in my case. I am trying to debug a simple NDK test project already the 4th day. Have investigated lots of material:
Android Native Development Kit Cookbook
Bunch of forums and tutorials
Videos
But can not hit a single damn breakpoint. Please help if you could do this ever.
The following is an excerpt from an tutorial I wrote for our internal Android development team. The bulk of which was derived from this blog: http://mhandroid.wordpress.com/
Important notes:
I use a Linux (Ubuntu 12.04) environment for my Android work.
I used the ADT Bundle for Linux, Build: v22.2.1-833290 (Eclipse IDE + Extras)
These steps are for debugging from a Java Activity into a JNI shared object.
I created test projects for this tutorial which won't be posted here, though references to those projects are present in the instructions that follow. You'll need an existing Android Application Project as well as a JNI shared object that is being called by your Java code.
Project Setup
Enable Debugging.
Open AndroidManifest.xml, select the Application tab, and set Debuggable=true. This will make the application debuggable even when it's running on a device that's running in user mode.
4. Build the Native Sources. From the Terminal, enter the project directory and enter:
ndk-build -B
You should see the following output:
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : DebuggingTestJNI <= com_sample_test_DebuggingTestActivity.cpp
StaticLibrary : libstdc++.a
SharedLibrary : libDebuggingTestJNI.so
Install : libDebuggingTestJNI.so => libs/armeabi/libDebuggingTestJNI.so
Clean the Project. In the Eclipse menu strip, select Project→Clean. It is good to perform this step anytime you change/build your native sources. This step ensures that Eclipse will rebuild your .apk.
Native Debug Setup
Create Java Debug Configuration. We need to create a debug configuration for stepping into Java source code.
In the Eclipse toolbar, you'll see a green bug. Click the little arrow next to the bug and select "Debug Configurations…".
Double-click "Android Application" in the tree structure on the left. This will create a template for a new Android Application Debug Configuration.
In the "Name:" field, name it "DebuggingTest Java Debug" to make sure you know this Configuration applies specifically to the DebuggingTest project, and targets your Java source.
Under "Project:", click the "Browse…" button and select DebuggingTest.
Click "Apply" to save your changes.
Click "Close".
In the Eclipse toolbar, click the little arrow next to the bug and select "Organize Favorites…".
Click "Add…"
Select "DebuggingTest Java Debug" and click "OK".
Your new debug configuration has now been created and added to your favorites. You can access your favorites by clicking the little arrow next to the bug in the toolbar. "DebuggingTest Java Debug" should be at the top of the list.
Run ndk-gdb.
In the Eclipse toolbar, click the little arrow next to the bug and select "DebuggingTest Java Debug". This will deploy and install the DebuggingTest.apk to your connected Android device and start the debugger.
Navigate to the DebuggingTest project directory in your Terminal and type the following:
ndk-gdb
If the command succeeds, you should see the following:
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-elf-linux".
(no debugging symbols found)
…
If you forgot to start debugging the application before this step, you get the following:
ERROR: Could not extract PID of application on device/emulator.
Are you sure the application is already started?
Consider using --start or --launch= if not.
If your Android.mk file is malformed or contains $(info) blocks, you get the following:
cp: target ./obj/local/armeabi/gdb.setup' is not a directory /home/Dev/NDK/ndk-gdb: 639: cannot create start DebuggingTest/jni/Android.mk end DebuggingTest/jni/Android.mk ./obj/local/armeabi/gdb.setup: Directory nonexistent /home/Dev/NDK/ndk-gdb: 640: cannot create start DebuggingTest/jni/Android.mk end DebuggingTest/jni/Android.mk ./obj/local/armeabi/gdb.setup: Directory nonexistent start: invalid option: -x Try start --help' for more information.
If ndk-gdb is already running, you get the following:
ERROR: Another debug session running, Use --force to kill it.
Resolve your ERRORs before continuing. ndk-gdb MUST run successfully.
Running ndk-gdb does not only ensure us that we are doing everything right so far, but also creates app_process, gdb.setup and libc.so files in the obj/local/armeabi/ sub-directory of our project. Those files will be needed in later steps.
Stop Debugging.
In your Terminal, type CTRL+Z to stop ndk-gdb.
In Eclipse, select Run → Terminate.
4. Create C/C++ Debug Configuration. We need to create a debug configuration for stepping into C/C++ source code.
In Eclipse, click the little arrow next to the bug and select "Debug Configurations…".
Double-click "C/C++ Application" in the tree structure on the left. This will create a template for a new C/C++ Application Debug Configuration.
In the "Name:" field, name it "DebuggingTest C and CPP Debug" to make sure you know this Configuration applies specifically to the DebuggingTest project, and targets your C/C++ source.
In the "Main" tab:
Click "Browse…" on the "C/C++ Application:" field.
Navigate to "/home/Test/testing/DebuggingTest/obj/local/armeabi/app_process" and click "OK".
Click "Browse…" on the "Project:" field.
Select "DebuggingTest" and click "OK".
Check the "Disable auto build" box.
At the bottom of the form, you'll see "Using GDB (DSF) … - Select other…". Press the "Select other…" button.
In the pop-up, check the "Use configuration specific settings" box.
Select "Standard Create Process Launcher" in the list and press "OK".
In the "Debugger" tab:
Click the combo-box on the "Debugger:" field and select "gdbserver".
Uncheck the "Stop on startup at:" box.
In the "Main" sub-tab:
Click "Browse…" on the "GDB debugger:" field.
Navigate to "/home/Dev/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb" and click "OK". This debugger is distributed with the Android NDK.
In the "GDB command file:" field, type "/home/Test/testing/DebuggingTest/obj/local/armeabi/gdb2.setup". The gdb2.setup file does not exist yet, but we'll create it shortly.
Check the "Use full file path to set breakpoints" box.
In the "Connection" sub-tab:
Set "Type:" to TCP
Set "Port number:" to 5039
Click "Apply" to save your changes.
Click "Close"
In the Eclipse toolbar, click the little arrow next to the bug and select "Organize Favorites…".
Click "Add…"
Select "DebuggingTest C and CPP Debug" and click "OK".
Your new debug configuration has now been created and added to your favorites. You can access your favorites by clicking the little arrow next to the bug in the toolbar. "DebuggingTest C and CPP Debug" should be at the top of the list.
Create gdb2.setup. Eclipse doesn't like the "target remote :5039" line in gdb setup file because it wants to enter this command internally (that is why you configured port 5039 in the previous step). Because the gdb.setup file is recreated by the NDK scripts, you have to copy it to the gdb2.setup and point Eclipse to the gdb2.setup file (which we did in the previous step).
In your File Explorer, navigate to "/home/Test/testing/DebuggingTest/obj/local/armeabi/".
Copy the "gdb.setup" file and then paste it into the same folder. The result should be a file named "gdb (copy).setup".
Rename "gdb (copy).setup" to "gdb2.setup".
Open gdb2.setup by double-clicking the file.
Replace "set solib-search-path ./obj/local/armeabi" with "set solib-search-path /home/Test/testing/DebuggingTest/obj/local/armeabi".
Replace "file ./obj/local/armeabi/app_process" with "file /home/Test/testing/DebuggingTest/obj/local/armeabi/app_process".
Remove the line that reads "target remote :5039".
Save and Close the file.
5. Create ndk-gdb-eclipse. One last Eclipse housekeeping item. Eclipse will run the gdb binary itself, so we have to remove the execution of gdb from ndk-gdb. We'll save the original content by doing another Copy-Paste-Rename.
In your File Explorer, navigate to "/home/Dev/NDK".
Copy the "ndk-gdb" file and then paste it into the same folder. The result should be a file named "ndk-gdb (copy)".
Rename "ndk-gdb (copy)" to "ndk-gdb-eclipse".
Open ndk-gdb-eclipse by doing a right-click → Open With Other Application …
Select Text Editor from the list of applications
In the file, locate the line that reads "$GDBCLIENT -x native_path $GDBSETUP" (probably at the very bottom) and comment it out by prefixing it with a "#" character.
Save and Close the file.
When Debugging native sources within the Eclipse IDE, we'll use ndk-gdb-eclipse instead of ndk-gdb.
Debugging/Stepping into Code
Step Into the Java Code!
Put a breakpoint in the DebuggingTestActivity.java file at line 20 (System.out.println("hello world!")).
Insert a breakpoint in your main Activity BEFORE any calls into native code are made. onCreate() is generally the best place for this.
Start the DebuggingTest application in Debug mode by clicking on the little arrow next to the bug and selecting "DebuggingTest Java Debug".
You'll see a pop-up on the screen labeled "Confirm Perspective Switch". Press "Yes" if you'd like it to switch to your Debug Perspective. I would recommend doing so.
At this point, you should have hit the breakpoint you set.
Warning: The breakpoint we just hit sits inside of the onCreate function. This function will be called AFTER all static loadLibrary calls have been made. Notice that outside of the onCreate function there is a System.loadLibrary("DebuggingTestJNI") inside of a static block. This loadLibrary call will execute before we enter our onCreate function, ensuring that our native symbols are loaded by the time we hit our initial breakpoint. It is imperative that we are stopped at a breakpoint before proceeding!
Step Into the C/C++ Code!
In your Terminal, navigate to the DebuggingTest directory and type the following command:
ndk-gdb-eclipse ← Remember that we created this file back in step 6
If successful, the command should complete without any response.
Go back to Eclipse and run your C/C++ debugger by clicking the little arrow next to the bug and selecting "DebuggingTest C and CPP Debug"
Note: When I do this, I see dozens of errors in my Eclipse console, but things still seem to be working…
Switch back to your Java Perspective.
Click the double arrows at the top right of right of your Eclipse window and select Java.
Open DebuggingTest/jni/com_sample_test_DebuggingTestActivity.cpp
Set a breakpoint in the first JNI function that will be called by your main Activity.
Click Run → Resume (F8)
You'll get the Perspective Switch message again, so feel free to switch back to the Debug Perspective.
You should have just hit the breakpoint we just set in the native code!
Congratulations!!!
At this point you should be able to take what you've learned and adapt it to existing projects you may have.
Related
When I try to export the game build for the Android platform, I started getting this error:
Within the Project Settings - Minimum API Level and Target API Level not get loaded anyhow!
While I have used all default Unity provided settings to export Android build.
Here is the image to illustrate this:
Now what to do to solve this error?
I have already read all the threads related to same problem but overall I can't able to find the solution that actually worked for me.
Project Settings > Player > Target API Level: Change "Automatic" to "Android 11" (or else)
Play once and Stop.
Change target api level to Automatic.
I don't know if the problem is the same, but this is how I handle it every time.
Edit: Now I just do this; I open the Other Settings Tab in Player Settings. Error appears in console. I Play and Stop it once and the error goes away (No need to change API Levels)
I just got the same error on MacOS using both Unity 2019.4.18.f1/2019.2.21.f1 and after a lot of messing around I think I might have figured some of it out.
At times ( don't know why ) Unity ( or something else ) starts resetting the JAVA_HOME environment variable to string empty when you start Unity. So even if you set JAVA_HOME via console or .bashrc/.zshrc depending on MacOS version it still doesn't work.
Some posts mentioned adding "/" to the end of the external tools SDK path. I think that just forces Unity to set the path again which makes it work for a while. But for me the the error just came back the second day.
I permanently fixed it adding an editor script to the Editor folder that changes the JAVA_HOME environment variable every time Unity starts/loads.
Here's the method for MacOS, just paste it in a C# script in the editor folder.
[InitializeOnLoadMethod]
static void SetJavaHome()
{
//Debug.Log(EditorApplication.applicationPath);
Debug.Log("JAVA_HOME in editor was: " + Environment.GetEnvironmentVariable("JAVA_HOME"));
string newJDKPath = EditorApplication.applicationPath.Replace("Unity.app", "PlaybackEngines/AndroidPlayer/OpenJDK");
if (Environment.GetEnvironmentVariable("JAVA_HOME") != newJDKPath)
{
Environment.SetEnvironmentVariable("JAVA_HOME", newJDKPath);
}
Debug.Log("JAVA_HOME in editor set to: " + Environment.GetEnvironmentVariable("JAVA_HOME"));
}
This worked for me :- Edit>Prefrences>In JDK Click copy path> then Uncheck JDK and Paste the copied path again in that and after OpenJDK add \
like this : Before : C:\Program Files\Unity\Hub\Editor\2020.1.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK
After : C:\Program Files\Unity\Hub\Editor\2020.1.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\
If that doesn't works than uncheck JDK,SDK,NDK,Gradle and Stop Gradle (all five boxes) than close unity. Open Again and Check all five boxes again.
I don't know why, but on mac os unity may use latest version of java if you have one.
If you have installed a few versions of java, you can just remove all except java v1.8.
You can check which version of java you have by typing in terminal /usr/libexec/java_home -V.
You should have 2 or more versions.
If you installed them with brew, you can just use brew to uninstall extra java packages.
Also you can update JAVA_HOME system variable by type
echo export "JAVA_HOME=$(/usr/libexec/java_home -v 1.8)" >> ~/.zshrc.
This solution worked for me.
I would like to extract my app in .apk format.
I add these script on my "package.json" page:
"build:development:android": "ionic cordova build android"
and "build:production:android": "ionic cordova build android --prod --release".
But, when I type the commands I have Errors.
What I should do to have my .apk file?
I am novice. Any help would be much appreciated. Thanks.
aha! I can see the problem in your code !
you are generating pages from ionic generate command! but if you see the file structure you will find that the page folder has its own module file! first delete that and then go to yourPage.ts file and delete the import of ionicPage and also remove the Annotation of ionic page.... Repeat this step for all pages which have this module file in them!
after that make sure your pages are imported in your app.module.ts
here lemme show you an example how it is done! consider I have a class called testerClass. its page structure on using
ionic g page testerClass will be as
delete that tester-class.module.ts
Step 2: AFTER deleting that you have to go into tester-class.ts and
remove the annotation and import of ionic page like shown in picture
**
NOTE!!make sure you run the build commands using admin/root pre villages (if you are not using root account just in case). in simple words search your cmd in windows search option right click and open as administrator
**
I think you encounter 2 problems and I will try to refer to them based on the screenshots.
Screenshot #1: I believe this is a permissions error, if you run the same command as an admin do you have the same result? In order to run it as an admin you will:
type 'cmd' in your search bar bottom at the windows bar
when the results emerge, right click on the command line and hit 'run as administrator'
Screenshot #2: This is a code error but it is simple to fix.
It seems that you have added the Album page via ionic generate page AlbumPage but then added that to your app.module.ts.
The result is that AlbumPage is declared on both app.module.ts and album.module.ts.
Since AlbumPage is built to be an Ionic Page (if you navigate in album.ts, right above Component annotation, you will se the IonicPage() annotation) you can remove it from the app.module.ts, and wherever you are referring to this page you can use the string of the name e.g. this.setRoot('AlbumPage'), instead of this.setRoot(AlbumPage), which also means that you do not have to import it.
I'm pulling my hair out trying to run a plain vanilla JUnit test on my Android project. I want to write a test for a POJO class that does not use any Android objects. In fact, I can't even get a test working that tests nothing!
I've read Google's "Testing Fundamentals" documentation, countless SO questions, and I think I've achieved a new height of stupidity, as I seem to have got less far than anyone in the history of Android.
My best guess at what I should be doing is this:
Create a new android project. I have already developed my prototype application with activities, POJOs and everything else - it runs fine on my phone. "MyExample"
In the Eclipse "Package Explorer" window, In the android project I want to test, in the "src" folder item, I right-click on the package item: "com.example.myexample", select "New" > "Other...",
Then in the popup window, select "Android" > "Android Test Project"
In "Project Name" text box, I enter "TestMyProject" and hit the "Next" button.
Select the "An existing Android Project" radio button, select "MyExample", and click the "Finish" button.
In "Package Explorer", expand "TestMyExample", right click on the package "com.example.myexample.test, select "New" > "JUnit Test Case".
In that popup window, enter name "MyTestCase".
Then I enter the following in the java file:
package com.example.myexample.test;
import junit.framework.TestCase;
public class MyTestCase extends TestCase {
public void testHelloWorld(){
assertTrue("Hello World Error", false);
}
}
Finally, I right-click the file in the package explorer, select "Run As" > "JUnit Test", then in the popup window, select "Use configuration specific settings", and select "Eclipse JUnit Launcher" and hit the "Ok" button.
I get this error in the console window:
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:136), pid=5216, tid=2756
# fatal error: Invalid layout of preloaded class
I seem to be getting a variety of "Invalid layout" errors depending on what procedure I use.
Please help!!
Unless there's a typo in your question, one possible problem is the way you are trying to run them.
Select Run As -> Android JUnit test instead of just JUnit test.
That's because these tests need to run on device, so the build is slightly more involved than for normal JUnit tests.
I'm guessing you've already read the docs, but it's an easy thing to miss.
I followed all the instruction given on stackflow, but unfortunately not able to generate doc file for my android project.
If I am not mentioning class path on last step of java doc generation, then getting "Android reference" error.
And if using it, then getting "javadoc: error - The -classpath option may be specified no more than once." error.
Using classpath:
-classpath "D:\Android 4.2 SDK\android_sdk\platforms\android-15\android.jar"
Am I using correct class path command ?
Please help me out.
Environment used:
Eclipse indigo
If you use Intellij IDEA go to Tools - Generate JavaDoc... Specify all the settings and set params: -bootclasspath [path]\android-sdk\platforms\android-{version}\android.jar -encoding UTF-8 -docencoding utf-8 -charset utf-8
More information is in this post.
Have You followed these steps (from www.mtholyoke.edu)? This works on my Project....if not and You get an error, please write here which error You get.
Project -> Generate Javadoc
In the "Javadoc command" field - browse to find javadoc.exe
• On the computers in the Clapp CS lab that is C:\JBuilderX\jdk1.4\bin\javadoc.exe
• On other computers it would be \bin\javadoc.exe
Check the box next to the project/package/file for which you are creating the javadoc
In the "Destination" field browse to find the desired destination (for example, the root directory of the current project).
Leave everything else as it is.
Click "Finish"
Javadoc should be in the destination folder. Open "index.html"
EDIT
I found a thread here in Stackoverflow with a lot of tipps, try this:
Javadoc in Eclipse failing to recognize packages
NEXT EDIT
It is only a possibility, but You specified Your classpath as:
"D:\Android 4.2 SDK\android_sdk\platforms\android-15\android.jar"
I know that eclipse got some problems with spaces inside a path. So the first part "Android 4.2 SDK" has to be specified without spaces, maybe here is the issue. But be aware, if You change this path, You have to set everywhere the new path where You have definded it.
I'm using the command line. I have also updated to Eclipse Kepler. It seems to execute javadoc differently? I'm investigating. But try this:
read the javadoc manual. It's confusing and doesn't tell you what to do, but, here's an example that should get you going.
Create a file called "options"
Add to the file this:
-d target-bin
-stylesheetfile style.css
-use
-splitindex
-windowtitle 'My Project Name Class Specification'
-doctitle 'My Project Name Class Specification'
-header '<b>My Project Name</b><br><font size="-1">0.1.5-alpha</font>'
-bottom 'Copyright 2014 My Company or Myself. All rights reserved.'
-group "Group Of Packages" "com.mypackage.*"
-overview overview.html
-exclude 'android'
-subpackages 'com.mypackage:android'
-charset utf-8
-encoding UTF8
-quiet
-sourcepath ../myProject/src;..\..\..\android-sdks\sources\android-19
Then on the command line type:
javadoc #options
Now, in Kepler, the "Generate Javadoc" dialog box says "What is the javadoc command line"...I suspect I'll have to type something like this. But don't know.
Hopefully this quick example will give you a start on how to get it done for your purposes.
By the way, I created a generic Eclipse project called "javadoc" in my Workspace so I could manage the files.
Hi iam new in Android and I am facing a problem in creating new project. After clicking finish button I am getting error as follow.
Failed to load properties file for project 'VDemo'
I got this in groups.google.com.See here
Here you have to set the environmental path's system variables. Which will
you get by *right clicking on My Computer properties Advanced Environmental
variables. *
** Then you select path option from System Variables* *and
select Edit option. Then u have to mentioned the *jdk's path as follows.
C:\Program Files\Java\jdk1.6.0_14\bin *after that give semi colon and set
the avd file path.
*
*
*C:\Documents and Settings\tpbhade.android\avd like this.** *Give the
semicolon. and click on ok button. Then u restart u r Eclipse. and go to
project menu unchecked Build Automatically option, and click on Build all
option. your problem will be solved.