omim: Android build problem

Hi, Thanks for your great job about making this nice project open source! I’m trying import project into android studio (Windows 8.1 64-bit) and I’ve done this steps till now (using this tutorial that seems inefficient at least to me) 1- Install QT 5.5 2- Install VS 2013 3- Install QT addin for VS and configure 4- add this part to PATH for qmake.exe E:\Qt\Qt5.5.1\5.5\msvc2013_64\bin\ and this part for clang C:\Program Files\LLVM\bin\ 5- Install Cygwin and add it to Path (it works now because I can run *.sh files inside cmd.exe) 6- Run set_up_android.py and face this error :

   File "C:\omim-master\tools\android\set_up_android.py", line 53
         print 'Could not find {0}, not an {1} path.'.format(test, title)

7- Copy a local.properties to root of android dir (that mentioned SDK and NDK-r10e I’ve downloaded before and located on a non-spaced direction) 8- Run ‘gradlew clean assembleWebRelease’ and faced this Error :

* What went wrong:
Task 'assembleWebRelease' not found in root project 'android'. Some candidates are: 'assembleRelease
', 'assembleX86Release'.

9- Run assembleRelease after doing some stuff:

What went wrong:
Execution failed for task ':cppBuildRelease'.
> Process 'command 'bash'' finished with non-zero exit value 1

Also running gradlew installRelease has errors too. 10- Importing .../omom-master/android to android studio and sync gradle has multiple errors that commenting ‘productFlavors’ section removed some errors and commenting continued till sync gradle has no error, this is my last build.gradle:

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:1.3.1'
  }
}

allprojects {
  repositories {
    jcenter()
    mavenCentral()
  }
}

apply plugin: 'com.android.application'
apply from: 'secure.properties'

dependencies {
  // android support libs
  compile 'com.android.support:support-v4:22.2.1'
  compile 'com.android.support:appcompat-v7:22.2.1'
  compile 'com.android.support:recyclerview-v7:22.2.1'
  compile 'com.android.support:design:22.2.1'
  // google play services
  compile 'com.google.android.gms:play-services-location:8.4.0'
  compile 'com.google.android.gms:play-services-analytics:8.4.0'
  compile 'com.google.android.gms:play-services-plus:8.4.0'
  // 3-party
  compile 'com.facebook.android:facebook-android-sdk:4.10.0'
  compile 'com.parse.bolts:bolts-android:1.4.0'
  compile 'com.parse:parse-android:1.13.0'
  compile 'com.google.code.gson:gson:2.6.1'
  compile fileTree(dir: '3rd_party', include: '*.jar')
  // BottomSheet
  compile project(":3rd_party:BottomSheet")
  // LinearLayoutManager allowing wrap_content of RecyclerView-s
  // TODO remove this library when default LinearLayoutManager will be fixed.
  compile 'org.solovyev.android.views:linear-layout-manager:0.5@aar'
}

def getDate() {
  def date = new Date()
  def formattedDate = date.format('yyMMdd')
  return formattedDate
}

project.ext.versionCodes = ['armeabi-v7a': 1, 'x86': 2]
project.ext.appId = 'com.mapswithme.maps.pro'

android {
  // All properties are read from gradle.properties file
  compileSdkVersion propTargetSdkVersion.toInteger()
  buildToolsVersion propBuildToolsVersion

  defaultConfig {
    // Default package name is taken from the manifest and should be com.mapswithme.maps
    versionCode propVersionCode.toInteger()
    versionName propVersionName
    minSdkVersion propMinSdkVersion.toInteger()
    targetSdkVersion propTargetSdkVersion.toInteger()
    applicationId project.ext.appId
    buildConfigField 'String', 'SUPPORT_MAIL', '"android@maps.me"'
    buildConfigField 'String', 'REVIEW_URL', '"market://details?id=com.mapswithme.maps.pro"'
    buildConfigField 'int', 'RATING_THRESHOLD', '5'
  }

  sourceSets.main {
    manifest.srcFile 'AndroidManifest.xml'
    res.srcDirs = ['res']
    java.srcDirs = ['src', '../3party/Alohalytics/src/android/java']
    // assets folder is auto-generated by tools/android/update_assets.sh, so we keep all static resources in separate folders.
    assets.srcDirs = ['assets']
    jniLibs.srcDirs = ['libs']
  }



  // Currently (as of 1.2.3 gradle plugin) ABI filters aren't supported inside of product flavors, so we cannot generate splitted builds only for Google build.
  // TODO check that feature when new gradle plugins will appear
  // connected bugreport https://code.google.com/p/android/issues/detail?id=178606
  splits.abi {
    enable true
    reset()
    include 'x86', 'armeabi-v7a'
    universalApk true
  }

  // TODO: Fix a lot of lint errors in our code
  lintOptions {
    abortOnError false
  }

  gradle.projectsEvaluated {
    android.applicationVariants.all { variant ->
      def task = variant.name.capitalize()
      project.task(type: Exec, "run${task}", dependsOn: "install${task}") {
        commandLine android.getAdbExe(), 'shell', 'am', 'start', '-n', "${applicationId}/com.mapswithme.maps.DownloadResourcesActivity"
      }

      variant.outputs.each { output ->
        if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
          def file = output.outputFile
          // version at the end of each built apk
          output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + android.defaultConfig.versionName + "-" + getDate() + ".apk"))
          // set different versionCodes for different ABIs
          int abiVersionCode = project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI)) ?: 0
          output.versionCodeOverride = (abiVersionCode * 1000) + android.defaultConfig.versionCode
        }
      }
    }
  }

//  signingConfigs {
//    mapswithme {
//      storeFile file(spropStoreFile)
//      storePassword spropStorePassword
//      keyAlias spropKeyAlias
//      keyPassword spropKeyPassword
//    }
//
//    mapswithmeDebug {
//      storeFile file('../tools/android/debug.keystore')
//      storePassword '12345678'
//      keyAlias 'debug'
//      keyPassword '12345678'
//    }
//  }

  buildTypes {
    debug {
      applicationIdSuffix '.debug'   // Allows to install debug and release builds together
      versionNameSuffix '-debug'
      jniDebuggable true           // Enable jni debug build
      zipAlignEnabled true
//      signingConfig signingConfigs.mapswithmeDebug
      android.sourceSets.debug.setRoot('flavors/debug')
    }

    release {
//      signingConfig signingConfigs.mapswithme
      minifyEnabled true
      shrinkResources true
      proguardFile('proguard-mwm.txt')
    }

    beta {
      applicationIdSuffix '.beta'
      versionNameSuffix '-beta'
//      signingConfig signingConfigs.mapswithme
      android.sourceSets.beta.setRoot('flavors/beta')
    }
  }

  // We don't compress these extensions in assets/ because our random FileReader can't read zip-compressed files from apk
  aaptOptions {
    noCompress 'txt', 'bin', 'html', 'png', 'json', 'mwm', 'ttf', 'sdf', 'ui'
    ignoreAssetsPattern "!.svn:!.git:!.DS_Store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"
  }

  // Enables new Java features in KitKat+ but needs Java 1.7 installed
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }
}

// Tasks needed to compile NDK part
apply plugin: 'base'

project.ext.PARAM_PARALLEL_TASK_COUNT = '-j' + (Runtime.runtime.availableProcessors() + 1)
project.ext.NDK_BUILD = android.getNdkDirectory().toString() + '/ndk-build'
if (System.properties['os.name'].toLowerCase().contains('windows'))
  project.ext.NDK_BUILD += ".cmd"

def archs = ['x86', 'armeabi-v7a-hard']
def buildTypes = [[ndkType: 'release', cppType: "production", flags : propReleaseNdkFlags], [ndkType: 'debug', cppType: "debug", flags : propDebugNdkFlags]]

buildTypes.each { type ->
  def suffix = type.ndkType.capitalize()
  createCppBuildTask(type.cppType, '', suffix)
  createNdkBuildTask(type.ndkType, '', suffix, type.flags)

  archs.each { arch ->
    suffix = type.ndkType.capitalize() + arch.capitalize()
    createCppBuildTask(type.cppType, arch, suffix)
    createNdkBuildTask(type.ndkType, arch, suffix, type.flags)
  }
}

def createCppBuildTask(buildType, arch, suffix) {
  return tasks.create(name: "cppBuild${suffix}", type: Exec, description: "Building ${buildType} version of static C++ libraries. Arch : ${arch}") {
    def args = ['bash', '../tools/autobuild/android.sh', buildType]
    if (!arch.isEmpty())
      args += arch
    commandLine args
  }
}

def createNdkBuildTask(buildType, arch, suffix, flags) {
  return tasks.create(name: "ndkBuild${suffix}", dependsOn: "cppBuild${suffix}", type: Exec, description: "Building ${buildType} version of jni. Arch : ${arch}") {
    def ndkParams = ([project.ext.NDK_BUILD, project.ext.PARAM_PARALLEL_TASK_COUNT] + flags.split(' ')).flatten()
    if (!arch.isEmpty())
      ndkParams += "NDK_ABI_TO_BUILD=${arch}"
    commandLine ndkParams
  }
}

task ndkBuildClean(type: Exec, description: 'Clean native jni libraries') {
  commandLine project.ext.NDK_BUILD, 'clean'
}

tasks.withType(JavaCompile) { compileTask ->
  if (compileTask.name.contains('Release') || compileTask.name.contains('Beta')) {
    compileTask.dependsOn ndkBuildRelease
  } else {
    compileTask.dependsOn ndkBuildDebug
  }
}

// NOTE : it does NOT clean built cpp static libs. cppClean does.
clean.dependsOn ndkBuildClean

// Cleans built native static libs.
task cppClean(type: Delete) << {
  buildTypes.each { type ->
    archs.each { arch ->
      delete "../../omim-android-${type.cppType}-${arch}"
    }
  }
}

// Tasks for generating obb files for Google Play
def unalignedFonts = "${propObbFontsOutput}.unaligned"
def unalignedWorlds = "${propObbWorldsOutput}.unaligned"

task obbClean(type: Delete) << {
  [propObbFontsOutput, propObbWorldsOutput, unalignedFonts, unalignedWorlds].each { file ->
    delete file
  }
}

task obbGenerate() {
  createObbGenerateTask('Main', propObbFonts.split(' '), unalignedFonts)
  createObbGenerateTask('Patch', propObbWorlds.split(' '), unalignedWorlds)
  createObbAlignTask('Main', unalignedFonts, propObbFontsOutput)
  createObbAlignTask('Patch', unalignedWorlds, propObbWorldsOutput)
}

obbGenerate.dependsOn obbClean, obbMainGenerate, obbPatchGenerate, obbMainAlign, obbPatchAlign

def createObbGenerateTask(type, data, name) {
  return tasks.create(name: "obb${type}Generate", type: Exec, description: 'Generate obb files') {
    commandLine ((['zip', '-0', '-j', name, data]).flatten())
  }
}

def createObbAlignTask(type, rawObb, alignedObb) {
  def sdkDir = "${android.getSdkDirectory().getAbsolutePath()}"
  def zipalignPath = sdkDir + File.separator + "build-tools" + File.separator +
                     propBuildToolsVersion + File.separator + "zipalign";

  return tasks.create(name: "obb${type}Align", dependsOn: "obb${type}Generate", type: Exec, description: 'Align obb files') {
    commandLine zipalignPath, '-v', '8', rawObb, alignedObb
  }
}

task obbPush(dependsOn: ['obbGenerate', 'obbPushMain', 'obbPushPatch']) {
  def obbPath = "/mnt/sdcard/Android/obb/${project.ext.appId}/"
  tasks.create(type: Exec, name: 'obbRemoveOnDevice') {
    commandLine android.getAdbExe(), 'shell', 'rm', "${obbPath}*.obb"
  }
  tasks.create(type: Exec, name: 'obbPushMain', dependsOn: 'obbRemoveOnDevice') {
    commandLine android.getAdbExe(), 'push', propObbWorldsOutput, "${obbPath}fonts.obb"
  }
  tasks.create(type: Exec, name: 'obbPushPatch', dependsOn: 'obbRemoveOnDevice') {
    commandLine android.getAdbExe(), 'push', propObbFontsOutput, "${obbPath}worlds.obb"
  }
}

task patchNdkR10E(type: Exec, description: 'Patches NDK r10e for bug described here https://code.google.com/p/android/issues/detail?id=179410') {
  def cxxabiPath = "${android.getNdkDirectory().getAbsolutePath()}/sources/cxx-stl/gabi++/src/cxxabi.cc"
  commandLine 'bash', '-c', "patch -p1 ${cxxabiPath} < ../tools/android/cxxabi.cc_patch"
}

11- Run the project and face this error:

Error:Execution failed for task ':cppBuildDebug'.
> Process 'command 'bash'' finished with non-zero exit value 1

Sorry for long post and thanks for your responsibility.

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 1
  • Comments: 42 (16 by maintainers)

Most upvoted comments

Have you run ./configure.sh script in the repo root? It should create all missing files.

Hi Guys,

I’ve just created a wiki page about building the android project. Please take a look at https://github.com/mapsme/omim/wiki/[Android]-How-to-build-project . And let me know if you have any questions and problems.

At this time it is not possible.

@trashkalmar actually i am running this app in ubuntu 16.04 In this initially i had run ./set_up_android.py file then i had run ./gradlew clean assembleWebRelease command in command line but it is showing below written error

home/dell/maps_me/omim-master/routing/routing_session.cpp:15:10: fatal error: ‘3party/Alohalytics/src/alohalytics.h’ file not found #include “3party/Alohalytics/src/alohalytics.h” ^ 1 error generated. Makefile:37830: recipe for target ‘…/out/production/tmp/routing/routing_session.o’ failed make[1]: *** […/out/production/tmp/routing/routing_session.o] Error 1 make[1]: *** Waiting for unfinished jobs… make[1]: Leaving directory ‘/home/dell/maps_me/omim-android-production-armeabi-v7a/routing’ Makefile:211: recipe for target ‘sub-routing-make_first’ failed make: *** [sub-routing-make_first] Error 2

  • echo ‘ERROR while building armeabi-v7a config’
  • exit 1 ERROR while building armeabi-v7a config :cppBuildRelease FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:cppBuildRelease’.

Process ‘command ‘bash’’ finished with non-zero exit value 1

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Can anyone please tell me what i should do now.

It can, if someone improves current script and ports it to Windows.

./configure.sh file is situated at the root of the project. You have to install cygwin at least.