Office Hours — Today, October 21

Yesterday, October 20

Oct 21
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:20 PM
Susheel
has entered the room
4:20 PM
Susheel
Hi Mark
Mark M.
hello, Susheel!
how can I help you today?
(BTW, happy Back to the Future Day!)
Susheel
I am currently trying to build this project I have cloned from my github to Android Studio...https://github.com/susheel17/android-s...
Thank you :)
This project has native class written in C
So I followed all guidelines to build NDK
I even included pre-built .so files
But i have an error 'Error:Cause: com.android.build.gradle.managed.AndroidConfig_Impl'
Mark M.
there should be more to the error message in your Gradle Console than that, I would think
Susheel
I promise that's all there is: obviously there is the gradle project refresh failed
Mark M.
then there's not a lot I can tell you
Susheel
hmm
Mark M.
this project is as old as the hills, though
Susheel
Yeah haha!
4:25 PM
Susheel
I removed the link to the so files from my build.gradle...it allows me to run the app on the device...but when I use the core functionality of the app which is in native code, the app crashes with this message
cannot locate symbol "tcgetattr" referenced by "libserial_port.so"...
Mark M.
right, that would indicate that the .so files cannot be found, which would make sense
have you recompiled the project's NDK code yourself?
Susheel
yes i had to remove some warnings by annotating but yes i did
do you mean build or recompile?
sorry
Mark M.
um, well, that'd amount to the same thing in this case
Susheel
oh ok...in that case I was able to build the project and run the app on the device
Mark M.
well, if that worked, what's the problem?
Susheel
but when I click a button that opens a serial port that's what use the native code and it crashes with the message I referenced earlier
so its not able to find the .so files
but I put them in a libs folder under project/app/
because I had pre-built .so files from my eclipse project for the same code
Mark M.
if your project is set up properly, you shouldn't need to do anything -- the build process will put them in the right spot for you
Susheel
So .so files are generated if my project is set up properly?
Mark M.
yes
4:30 PM
Mark M.
first, I would recommend having this stuff be a separate library module, rather than trying to merge it in with your main app code
Susheel
right
Mark M.
then, take a look at projects with the NDK setup in there, such as https://github.com/commonsguy/cwac-anddown
I use the ndk closure in build.gradle for the library module
and, since this project is still somewhat Eclipse-friendly, I fix up the main sourceset to point to where the JNI files are
from there, it builds, runs, puts the binaries in the right spot, and it all gets picked up by the demo/ app
Susheel
so I put this block in my build.gradle file to tell the ndk location
View paste
 android.ndk {
        moduleName = "serial_port"
        ldLibs = ["android","log"]
    }
Mark M.
I haven't needed ldLibs yet, so I can't tell you if that's right or wrong
(I do very little C/C++ work personally)
Susheel
that is just because there are log comments in the c file
oh
Can I request some video chat time with you asap to help me on this project? All I need is to be able to build and run the core serial port functionality.
Mark M.
to be honest, it is *very* unlikely to be worth your while
Susheel
oh!
4:35 PM
Mark M.
again, outside of this one project, and a book demo or two, I do nothing with the NDK
Susheel
got it
so coming back to this error 'cannot locate symbol "tcgetattr" referenced by "libserial_port.so"...
you think there is something wrong with the way I am linking my jni files?
Mark M.
possibly
Susheel
gotcha
Mark M.
either the .so files are not making it into the APK, or they are not being loaded properly at runtime
have you manually inspected your APK file to see if your .so files seem to be in there?
Susheel
and the cause is most likely the jni files?
not yet
Mark M.
I can't give you a "most likely" on anything regarding the NDK
again, I very rarely use it
Susheel
got it
Mark M.
part of the reason I am pointing you to AndDown is that it is my best example of NDK code, that I am familiar with and that works
Susheel
I will read that right away...
Mark M.
so, for example, you could compare your APK to the AndDown demo app APK
and see if the .so files seem to be in equivalent spots
Susheel
please can you tell me where the apk is generated in Android Studio?
Mark M.
app/build/outputs/apk, IIRC
Susheel
awesome thanks
Mark M.
where app/ is your application module
Susheel
right
Mark M.
if the .so files are in the right spot in your APK, try running the app again, and see if there are any LogCat messages in the milliseconds before your crash that complain about linking erorrs
er, errors
in that case, perhaps something is up with ldLibs, which AndDown is not using
4:40 PM
Mark M.
and once you get past that, I'm largely out of suggestions
Susheel
Thank you very much for all your help
Mark M.
sorry I didn't have a more conclusive answer for you
Susheel
no problem. you've given me a lot of pointers. Thank you Mark!
but I have one more question about examining the apk...how would I be able to view the contents of an apk?
Mark M.
it's just a ZIP file
Susheel
oh!
Mark M.
my Ubuntu environment just lets me double-click on it to view the contents; I forget if I set that up myself or Ubuntu just recognizes the file extension
Susheel
I am developing on a mac
there's probably no feature like that for MacOS
4:45 PM
Mark M.
I would hope OS X lets you teach it what to do for unrecognized file extensions
regardless, if nothing else, use the commandline unzip utility
Susheel
right
thanks
4:50 PM
Susheel
I have one other question for you
Mark M.
OK
Susheel
I have ADT already running on my other machine
I was wondering if I installed gradle plugin, would I be able to import all gradle android libraries just by including the dependencies?
Mark M.
well, ADT has nothing to do with Gradle
unless there have been some changes on the Eclipse/ADT side that I am unaware of
now, you can build an Eclipse/ADT project with Gradle, but it takes a build.gradle file that maps the directory structure properly
ironically, those AndDown projects demonstrate this, as I have not yet cut them over to be Android Studio-centric
Susheel
right...is that process covered in the book anywhere?
oh
4:55 PM
Mark M.
I think I may still have material on that
though I am slowly de-Eclipse-ing the book
Susheel
cool
Mark M.
I'd just look at the sourcesets closure in one of those projects and copy it over
Susheel
right
but I was wondering if there is tutorial to install the gradle plugin for ADT in your book but I guess it is easy to look for one on the web
Mark M.
I am not aware that a Gradle plugin for ADT even exists
Eclipse's Andmore project will eventually take up the mantle of Eclipse-based Android development
but I haven't been tuned into that for a while
so I do not know its status
Susheel
oh
Mark M.
and with Google dropping Eclipse support at the end of the year, I am counselling everybody to have a plan, pronto
if Andmore is ready, move to it
Susheel
right
Mark M.
otherwise, get over to Android Studio
Susheel
right
So did you suggest me to download your anddown project, import it to AS and build it and examine the apk?
Mark M.
yes
Susheel
earlier when we were talking about comparing apk contents
cool
5:00 PM
Susheel
question on a separate subject....does the book cover transitions apis or any of the new animations apis added in lollipop like circular reveal etc?
Mark M.
no and no
Susheel
hmm
Mark M.
someday, perhaps, but not high on my list at the moment
and that's a wrap for today's chat
the next one is tomorrow at 9am US Eastern
Susheel
Thank you for all your help
have a good night!
Mark M.
this transcript will go up on https://commonsware.com/office-hours/ shortly
have a pleasant day!
Susheel
has left the room
Mark M.
turned off guest access

Yesterday, October 20

 

Office Hours

People in this transcript

  • Mark Murphy
  • Susheel