News

Build and reference Rajawali 3D engine using Android Studio

posted 29 Apr 2014, 04:35 by Simon Šander   [ updated 29 Apr 2014, 23:43 ]

Introduction

I have tried to get Rajawali 3D engine work with Android Studio. After some searching on Google with no success, I have realized that I'll have to do it myself.

Prerequisites

  • Installed latest version of Android Studio

The hard way

  1. Go to GitHub page of Rajawali 3D engine source (https://github.com/MasDennis/Rajawali)
  2. Click Download ZIP button and save it to your computer
  3. Unzip it to Rajawali folder (let say c:\temp\Rajawali) go to that folder and you should see this



  4. Start Android Studio and select File -> New project and create new blank project (see image below)



  5. Go to forder where project was created (for this example it is c:\temp\MyApplication2\)
  6. You should see structure like this


  7. Now copy folder gradle and files gradlew.bat, build.gradle and local.properties to folder c:\temp\Rajawali


  8. Copy and paste thext below to gradle.build file

    buildscript {
        repositories {
            mavenCentral()
        }

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

    apply plugin: 'android-library'

    repositories {
        mavenCentral()
        mavenLocal()    
    }

    android {
        compileSdkVersion 19

        buildToolsVersion "19.0.3"

        defaultConfig {
            versionCode 1
            versionName "1.0"
            minSdkVersion 14
            targetSdkVersion 19
        }

        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                res.srcDirs = ['res']
            }
        }

        lintOptions {
            abortOnError false
        }
    }


  9. Run Android Studio again and select Import project. Navigate to c:\temp\Rajawali and select build.gradle file.
  10. Click Sync Project With Gradle Files 

  11. Open Command prompt and navigate to c:\temp\Rajawali
  12. Type gradlew build
  13. If everything was done right project should compile and you'll get new build folder. There is folder called libs inside that contains Rajawali.aar library.
  14. You can now install Rajawali.aar library to your local maven repository like this:

    mvn install:install-file -Dfile=.\build\libs\Rajawali.aar -DgroupId=rajawali.framework -DartifactId=rajawaliframework -Dversion=1 -Dpackaging=aar

  15. Now you can put maven reference to jour local Rajawali into build.gradle file of your project

    android {
        dependencies {
            compile 'rajawali.framework:rajawaliframework:1'
        }
    }

  16. Build your project.

The easy way

You can just download Android Studio ready version from here https://github.com/sajmons/Rajawali and run gradlew build from Command prompt for same effect.

If you find this tutorial useful please share it with your friends.

Android gradle build with free and paid flavors

posted 23 Oct 2013, 12:57 by Simon Šander   [ updated 23 Oct 2013, 23:30 ]

Problem

My goal was to have two different flavors for my Android application build. One for free and one for paid version. Paid version would be published to slide.me and Amazon app store.

I'm new to gradle build system, so my first attempt was quite good but not perfect. I have managed to get two different flavors but the problem was that advertising libraries that should be linked only to the free version, were linked to the paid version too.

Amazon had no problems with that and they accepted both version, but guys at slide.me were a lot more demanding. They run analysis of apk that I have send them and they discovered traces of advertising libraries. With slide.me it's not enough just to remove ads from app, they demand that there is no traces of advertising libraries inside apk.

Solution

After a lot of Goggling I have finally came up with solution that works great. I will not go into details because final gradle build file will probably help you more than thousand words.

Here it is. Gradle build file with many flavors and with custom dependencies for each of them. I think It can be a great start for your own Android project.

Project setup



gradle.build

buildscript {
    repositories {
        mavenCentral()
    }

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

apply plugin: 'android'

repositories {
    mavenCentral()
    mavenLocal()
}

android {
    compileSdkVersion 18

    buildToolsVersion "18.0.1"

    defaultConfig {
        versionCode 26
        versionName "2.0"
        minSdkVersion 9
        targetSdkVersion 18
        packageName 'com.example.myexample'
    }

    signingConfigs {
        debug {
            storeFile file("path to your debug store")
        }

        release {
            storeFile file("path to your release store")
            storePassword ""
            keyAlias ""
            keyPassword ""
        }
    }

    buildTypes {
        debug {
            packageNameSuffix '.debug'
            versionNameSuffix '-DEBUG'
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.release
        }
    }

    flavorGroups 'market', 'version'

    productFlavors {
        google {
            flavorGroup 'market'
        }
        amazon {
            flavorGroup 'market'
        }
        slideme {
            flavorGroup 'market'
        }
        free {
            flavorGroup "version"
        }
        paid {
            flavorGroup "version"
            packageName = android.defaultConfig.packageName + ".paid"
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }
        amazon {
            assets.srcDirs = ['src/amazon/assets']
            res.srcDirs = ['src/amazon/res']
            java.srcDirs = ['src/amazon/java']
        }
        slideme {
            assets.srcDirs = ['src/slideme/assets']
            res.srcDirs = ['src/slideme/res']
            java.srcDirs = ['src/slideme/java']
        }
        free {
            manifest.srcFile 'src/free/AndroidManifest.xml'
            assets.srcDirs = ['src/free/assets']
            res.srcDirs = ['src/free/res']
            java.srcDirs = ['src/free/java']
        }
        paid {
            assets.srcDirs = ['src/paid/assets']
            res.srcDirs = ['src/paid/res']
            java.srcDirs = ['src/paid/java']
        }
    }
}

dependencies {
    compile fileTree(dir: 'src/main/libs', include: '*.jar')
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.android.support:appcompat-v7:18.0.+'    
    freeCompile fileTree(dir: 'src/free/libs', include: '*.jar')
}

1-2 of 2