Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Shell commands on Android
Qt 6.11 is out! See what's new in the release blog

Shell commands on Android

Scheduled Pinned Locked Moved Solved Mobile and Embedded
19 Posts 3 Posters 7.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #10

    Wait... Is it tar that is failing or chown in this case ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • FerniF Offline
      FerniF Offline
      Ferni
      wrote on last edited by Ferni
      #11

      How can I check that? I'm only using QProcess with these parameters

      QString program = "tar";
      QStringList args;
      args << "-xvf" << outputTar;
      proc->execute(program, args);
      

      where proc is my QProcess and outputTar is my tar file(full path) made by QProcess with "-cvf" as arguments

      Why can I create a tar file but not extract it? I tried also with a tar file created in my PC but the result is the same. I found that I have to set the working directory in QProcess and I set

      proc->setWorkingDirectory(dir);
      

      where dir is QStandardPaths::writableLocation(QStandardPaths::DataLocation), same location where tar file was created and where I want to unpack it.

      EDIT:
      @SGaist
      I change the default location to QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) and I found out that my tar file is empty. I tested my code in Linux and the only difference is the path that I use as working directory. Is it even possible to use TAR command in Android? Where can I find a list with the usable commands?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #12

        Are you only interested in creating files archives ? If so you should rather take a look at KArchive.

        AFAIK, Android doesn't use any standard Linux shell and even so, it might be different from one version to the other.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • FerniF Offline
          FerniF Offline
          Ferni
          wrote on last edited by
          #13

          Yeap, that would be my option. The problem is that I already have some code that was thought for Linux . If I want to implement that with a library I should process each command and its arguments and then do something to similar to the command with the specific arguments.

          I found this and it seems that there is no TAR command so I will close this post :(

          Also, I found a new approach. I compiled BusyBox and running commands with adb shell is working perfectly but I cannot make it work within my Qt application. I'm trying with these lines from java but I'm not sure if it's not working because the executable doesn't have the necessary permissions or if it's not even called. Could you point me where to look to run external executables from a Qt application? Using BusyBox will solve all my implementations problems

                      String myExec = "/data/local/tmp/busybox touch /sdcard/fromBB.txt";
                      Process process = Runtime.getRuntime().exec(myExec);
          
          1 Reply Last reply
          0
          • FerniF Offline
            FerniF Offline
            Ferni
            wrote on last edited by
            #14

            @SGaist
            Sorry to bother you but I decided to make a mixed solution: normal commands will run with console and compressed files will be run with a 3rd party library.

            I tried to use KArchive as you suggested but I'm stuck, I can't even compile it for my pc (linux). Could you point me where to find a tutorial? As the library is written in Qt I was expected a .pro file but I found a CMakeList instedad :/

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #15

              You need one additional thing: the extra-cmake-modules

              Use -DCMAKE_PREFIX_PATH=path/to/qtbase/lib/cmake/ to tell cmake where to find your Qt version and the do the same for karchive.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • FerniF Offline
                FerniF Offline
                Ferni
                wrote on last edited by
                #16

                Hey @SGaist thanks! Just adding that line solve the problem. I compiled and I'm testing the library. Do you know what are the changes that I need to compile KArchive for Android? I tried to make a .pro with the sources but I got a lot of missing files errors and I'm kind of lost with CMake.

                1 Reply Last reply
                0
                • FerniF Offline
                  FerniF Offline
                  Ferni
                  wrote on last edited by
                  #17

                  Oks... some missing paths for Android. After I added them I got a CMake error:

                  /usr/share/cmake-3.2/Modules/CMakeTestCXXCompiler.cmake:54: error: The C++ compiler "/opt/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-4.9.x" is not able to compile a simple test program. It fails with the following output: Change Dir: /home/ferni/QtBuild/QtKArchive/output/android/CMakeFiles/CMakeTmp
                  

                  I run the standalone toolchain script from NDK and using it could run CMake.

                  /opt/android-ext/bin/arm-linux-androideabi-gcc
                  

                  The problem now comes when I build. I left here the compile output

                  15:56:11: Running steps for project KArchive...
                  15:56:11: Persisting CMake state...
                  15:56:13: Starting: "/usr/bin/cmake" --build . --target all -- -j8
                  Scanning dependencies of target KF5Archive_automoc
                  [  7%] Automatic moc for target KF5Archive
                  [  7%] Built target KF5Archive_automoc
                  Scanning dependencies of target KF5Archive
                  [ 14%] [ 21%] [ 28%] [ 35%] Building CXX object src/CMakeFiles/KF5Archive.dir/kar.cpp.o
                  Building CXX object src/CMakeFiles/KF5Archive.dir/kcompressiondevice.cpp.o
                  [ 42%] Building CXX object src/CMakeFiles/KF5Archive.dir/karchive.cpp.o
                  Building CXX object src/CMakeFiles/KF5Archive.dir/kfilterbase.cpp.o
                  Building CXX object src/CMakeFiles/KF5Archive.dir/kfilterdev.cpp.o
                  [ 50%] [ 57%] [ 64%] Building CXX object src/CMakeFiles/KF5Archive.dir/klimitediodevice.cpp.o
                  Building CXX object src/CMakeFiles/KF5Archive.dir/knonefilter.cpp.o
                  Building CXX object src/CMakeFiles/KF5Archive.dir/kgzipfilter.cpp.o
                  [ 71%] Building CXX object src/CMakeFiles/KF5Archive.dir/ktar.cpp.o
                  [ 78%] Building CXX object src/CMakeFiles/KF5Archive.dir/kzip.cpp.o
                  [ 85%] Building CXX object src/CMakeFiles/KF5Archive.dir/krcc.cpp.o
                  [ 92%] Building CXX object src/CMakeFiles/KF5Archive.dir/loggingcategory.cpp.o
                  [100%] Building CXX object src/CMakeFiles/KF5Archive.dir/KF5Archive_automoc.cpp.o
                  Linking CXX shared library libKF5Archive.so
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchive::KArchive(QString const&): error: undefined reference to 'operator new(unsigned int)'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchive::KArchive(QIODevice*): error: undefined reference to 'operator new(unsigned int)'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchive::~KArchive(): error: undefined reference to 'operator delete(void*)'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchive::~KArchive(): error: undefined reference to 'operator delete(void*)'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchive::~KArchive(): error: undefined reference to 'operator delete(void*)'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchive::createDevice(QFlags<QIODevice::OpenModeFlag>): error: undefined reference to 'operator new(unsigned int)'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchive::createDevice(QFlags<QIODevice::OpenModeFlag>): error: undefined reference to 'operator new(unsigned int)'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchiveEntry::~KArchiveEntry(): error: undefined reference to 'operator delete(void*)'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchiveDirectory::copyTo(QString const&, bool) const: error: undefined reference to '__dynamic_cast'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:function KArchiveDirectory::copyTo(QString const&, bool) const: error: undefined reference to '__dynamic_cast'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:vtable for KArchive: error: undefined reference to '__cxa_pure_virtual'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:vtable for KArchive: error: undefined reference to '__cxa_pure_virtual'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:vtable for KArchive: error: undefined reference to '__cxa_pure_virtual'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:vtable for KArchive: error: undefined reference to '__cxa_pure_virtual'
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:typeinfo for KArchiveDirectory: error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info'
                  /opt/android-ext3/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function (see go/missingkeymethod)
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:typeinfo for KArchiveFile: error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info'
                  /opt/android-ext3/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function (see go/missingkeymethod)
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:typeinfo for KArchiveEntry: error: undefined reference to 'vtable for __cxxabiv1::__class_type_info'
                  /opt/android-ext3/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function (see go/missingkeymethod)
                  CMakeFiles/KF5Archive.dir/karchive.cpp.o:karchive.cpp:typeinfo for KArchive: error: undefined reference to 'vtable for __cxxabiv1::__class_type_info'
                  /opt/android-ext3/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function (see go/missingkeymethod)
                  CMakeFiles/KF5Archive.dir/kar.cpp.o:kar.cpp:function KAr::openArchive(QFlags<QIODevice::OpenModeFlag>): error: undefined reference to 'operator delete[](void*)'
                  CMakeFiles/KF5Archive.dir/kar.cpp.o:kar.cpp:function KAr::openArchive(QFlags<QIODevice::OpenModeFlag>): error: undefined reference to 'operator delete[](void*)'
                  CMakeFiles/KF5Archive.dir/kar.cpp.o:kar.cpp:function KAr::openArchive(QFlags<QIODevice::OpenModeFlag>): error: undefined reference to 'operator delete[](void*)'
                  CMakeFiles/KF5Archive.dir/kar.cpp.o:kar.cpp:function KAr::openArchive(QFlags<QIODevice::OpenModeFlag>): error: undefined reference to 'operator new[](unsigned int)'
                  CMakeFiles/KF5Archive.dir/kar.cpp.o:kar.cpp:function KAr::openArchive(QFlags<QIODevice::OpenModeFlag>): error: undefined reference to 'operator delete[](void*)'
                  CMakeFiles/KF5Archive.dir/kar.cpp.o:kar.cpp:typeinfo for KAr: error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info'
                  /opt/android-ext3/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function (see go/missingkeymethod)
                  CMakeFiles/KF5Archive.dir/kcompressiondevice.cpp.o:kcompressiondevice.cpp:typeinfo for KCompressionDevice: error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info'
                  /opt/android-ext3/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function (see go/missingkeymethod)
                  CMakeFiles/KF5Archive.dir/kfilterbase.cpp.o:kfilterbase.cpp:typeinfo for KFilterBase: error: undefined reference to 'vtable for __cxxabiv1::__class_type_info'
                  /opt/android-ext3/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function (see go/missingkeymethod)
                  CMakeFiles/KF5Archive.dir/kzip.cpp.o:kzip.cpp:function KZip::closeArchive(): error: undefined reference to 'operator new[](unsigned int)'
                  CMakeFiles/KF5Archive.dir/kzip.cpp.o:kzip.cpp:function KZip::doPrepareWriting(QString const&, QString const&, QString const&, long long, unsigned short, QDateTime const&, QDateTime const&, QDateTime const&): error: undefined reference to 'operator new[](unsigned int)'
                  CMakeFiles/KF5Archive.dir/loggingcategory.cpp.o:loggingcategory.cpp:function KArchiveLog(): error: undefined reference to '__cxa_guard_acquire'
                  CMakeFiles/KF5Archive.dir/loggingcategory.cpp.o:loggingcategory.cpp:function KArchiveLog(): error: undefined reference to '__cxa_guard_release'
                  collect2: error: ld returned 1 exit status
                  make[2]: *** [src/libKF5Archive.so.5.33.0] Error 1
                  make[1]: *** [src/CMakeFiles/KF5Archive.dir/all] Error 2
                  make: *** [all] Error 2
                  15:56:16: The process "/usr/bin/cmake" exited with code 2.
                  Error while building/deploying project KArchive (kit: Android)
                  When executing step "Make"
                  15:56:16: Elapsed time: 00:05.
                  

                  What am I doing wrong?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #18

                    Android will require a bit of work. I'd start here: https://community.kde.org/Android

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • FerniF Offline
                      FerniF Offline
                      Ferni
                      wrote on last edited by
                      #19

                      I could finally compile KArchive for Android. I just had to make a .pro with the right files and include the sources to my project. I left it here! Don't forget to add config-compression.h, loggingcategory.h and karchive_export.h, some files need those headers.

                      I have tested for ZIP and TAR under Linux and Android and it's working perfectly!!

                      TARGET = KArchive
                      TEMPLATE = lib
                      QT       -= gui
                      
                      INCLUDEPATH += ../../include
                      
                      SOURCES += \
                          ../../src/karchive.cpp \
                          ../../src/kar.cpp \
                          ../../src/kcompressiondevice.cpp \
                          ../../src/kfilterbase.cpp \
                          ../../src/kfilterdev.cpp \
                          ../../src/kgzipfilter.cpp \
                          ../../src/klimitediodevice.cpp \
                          ../../src/knonefilter.cpp \
                          ../../src/ktar.cpp \
                          ../../src/kzip.cpp
                          ../../src/krcc.cpp \
                      
                      HEADERS += \
                          ../../include/karchive.h \
                          ../../include/kar.h \
                          ../../include/kcompressiondevice.h \
                          ../../include/kfilterbase.h \
                          ../../include/kfilterdev.h \
                          ../../include/kgzipfilter.h \
                          ../../include/klimitediodevice_p.h \
                          ../../include/knonefilter.h \
                          ../../include/ktar.h \
                          ../../include/kzip.h
                          ../../include/krcc.h \
                      
                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved