{"id":2145,"date":"2014-07-28T02:50:58","date_gmt":"2014-07-27T22:50:58","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=2145"},"modified":"2014-07-28T22:43:37","modified_gmt":"2014-07-28T18:43:37","slug":"2145","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=2145","title":{"rendered":"Running Android app on device using Gradle"},"content":{"rendered":"<p>Here I will show you, how I managed to build and run an Android app via command line (Terminal, since I use Mac) using Gradle and how I start a resulting app on the device (Google Nexus 5 with Android 4.4.2) automatically. I had to solve two major problems to achieve this. <\/p>\n<p><strong>The first problem<\/strong> is with Gradle version: <em>last version of Gradle is not compatible with the last version of Android Plugin. <\/em><br \/>\n<strong>The second problem<\/strong> is with custom task to run app on device: <em>you have to put the correct package and activity names. <\/em><\/p>\n<p>The final result looks like this: <\/p>\n<pre>\r\n~\/Documents\/Multiverse: $ gradle appStart\r\n<\/pre>\n<p>Where <strong>Multiverse<\/strong> is the root folder of my project and the name of the project, <strong>appStart<\/strong> &#8211; custom Gradle task that builds and runs an app on device.<br \/>\nGradle loads all dependencies, builds app, makes a lint check and starts and app on your device automatically. Yahoo! This is how it looks on Terminal:<\/p>\n<pre>\r\n\tpkg: \/data\/local\/tmp\/Multiverse-debug.apk\r\nSuccess\r\n:appStart\r\nStarting: Intent { cmp=com.alwawee.multiverse\/com.alwawee.main.MainActivity }\r\n\r\nBUILD SUCCESSFUL\r\n\r\nTotal time: 13.475 secs\r\n<\/pre>\n<p>However, I should notice, that this works slower than just running via Eclipse: as you see it takes at least 13 seconds for a little project on Macbook Pro Retina Display Late 2012. <\/p>\n<p>First of all you need to install a correct version of Gradle. If you just download the latest version, your Android plugin will not work. You have to get a version, for instance, 1.10, not 2.0. Also you need to setup PATH variable, so that you will have bin folder of Gradle and android sdks tools there:<\/p>\n<pre>\r\n~\/Documents\/Multiverse: $ vim ~\/.bash_profile\r\n\r\nexport PATH=\/Users\/Denis\/gradle-1.10\/bin:$PATH\r\nexport PATH=\/Users\/Denis\/android-sdks\/platform-tools:$PATH\r\nexport PATH=\/Users\/Denis\/android-sdks\/tools:$PATH\r\n\r\n~\/Documents\/Multiverse: $ source ~\/.bash_profile\r\n<\/pre>\n<p>Then I created a gradle build file:<\/p>\n<pre>\r\nbuildscript {\r\n    repositories {\r\n        mavenCentral()\r\n    }\r\n\r\n    dependencies {\r\n        classpath 'com.android.tools.build:gradle:0.11.1'\r\n    }\r\n}\r\n\r\napply plugin: 'android'\r\n\r\ndependencies {\r\n    compile files('libs\/android-support-v4.jar')\r\n    compile files('libs\/androidannotations-api-3.0.1.jar')\r\n    compile files('libs\/commons-lang3-3.1.jar')\r\n    compile files('libs\/flurryAnalytics_3.4.0.jar')\r\n    compile files('libs\/libGoogleAnalyticsServices.jar')\r\n}\r\n\r\nandroid {\r\n    compileSdkVersion 19\r\n    buildToolsVersion \"19.1\"\r\n}\r\n\r\nandroid {\r\n    sourceSets {\r\n        main {\r\n            manifest.srcFile 'AndroidManifest.xml'\r\n            java.srcDirs = ['src']\r\n            resources.srcDirs = ['src']\r\n            aidl.srcDirs = ['src']\r\n            renderscript.srcDirs = ['src']\r\n            res.srcDirs = ['res']\r\n            assets.srcDirs = ['assets']\r\n        }\r\n\r\n        androidTest.setRoot('tests')\r\n    }\r\n}\r\n\r\n\/*android {\r\n      lintOptions {\r\n          abortOnError false\r\n      }\r\n}*\/\r\n\r\ntask appStart(type: Exec, dependsOn: ':installDebug') {\r\n    \/\/ linux, mac \r\n    commandLine 'adb', 'shell', 'am', 'start', '-n', 'com.alwawee.multiverse\/com.alwawee.main.MainActivity'\r\n\r\n    \/\/ windows\r\n    \/\/ commandLine 'cmd', '\/c', 'adb', 'shell', 'am', 'start', '-n', 'com.alwawee.multiverse\/com.alwawee.main.MainActivity'      \r\n}\r\n<\/pre>\n<p>Here <strong>com.alwawee.multiverse<\/strong> is the package name of the application.<br \/>\nAnd <strong>com.alwawee.main.MainActivity<\/strong> is the full Activity name, that the application starts from. This is how my project tree looks like:<br \/>\n<a href=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/07\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-2014-07-28-\u0432-1.51.29.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/07\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-2014-07-28-\u0432-1.51.29.png\" alt=\"\u0421\u043d\u0438\u043c\u043e\u043a \u044d\u043a\u0440\u0430\u043d\u0430 2014-07-28 \u0432 1.51.29\" width=\"428\" height=\"290\" class=\"aligncenter size-full wp-image-2159\" srcset=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/07\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-2014-07-28-\u0432-1.51.29.png 428w, https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/07\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-2014-07-28-\u0432-1.51.29-300x203.png 300w\" sizes=\"auto, (max-width: 428px) 100vw, 428px\" \/><\/a><\/p>\n<p>This is a part of the Manifest file:<\/p>\n<pre>\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    package=\"com.alwawee.multiverse\"\r\n    android:versionCode=\"2\"\r\n    android:versionName=\"1.0.8\" >\r\n    \r\n    ...\r\n        \r\n        <activity\r\n            android:name=\"com.alwawee.main.MainActivity\"\r\n            android:label=\"@string\/app_name\">\r\n    ...\r\n<\/pre>\n<p>At the end there is a custom task <strong>appStart<\/strong>. It is important to correctly write the package name before class name. I thought that the package name is the package name for MainActivity class. I was wrong. It&#8217;s a name for a whole app&#8217;s package name. You can find it at the root node of your Manifest file. <\/p>\n<p>Notes on commented code: use <strong>abortOnError false<\/strong> if you have any serious problems with lint and don&#8217;t want to solve them. Uncomment the line about Windows, if you use Windows.<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/24985996\/running-android-app-on-device-using-gradle\" target=\"_blank\">This is a StackOverflow question<\/a>, I asked to reach this goal.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here I will show you, how I managed to build and run an Android app via command line (Terminal, since I use Mac) using Gradle and how I start a resulting app on the device (Google Nexus 5 with Android 4.4.2) automatically. I had to solve two major problems to achieve this. The first problem [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[188,83],"class_list":["post-2145","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-gradle"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Running Android app on device using Gradle - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=2145\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running Android app on device using Gradle - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"Here I will show you, how I managed to build and run an Android app via command line (Terminal, since I use Mac) using Gradle and how I start a resulting app on the device (Google Nexus 5 with Android 4.4.2) automatically. I had to solve two major problems to achieve this. The first problem [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=2145\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-27T22:50:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-07-28T18:43:37+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.alwawee.com\/?attachment_id=1982\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"Running Android app on device using Gradle\",\"datePublished\":\"2014-07-27T22:50:58+00:00\",\"dateModified\":\"2014-07-28T18:43:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145\"},\"wordCount\":397,\"commentCount\":1,\"keywords\":[\"Android\",\"Gradle\"],\"articleSection\":[\"Android\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145\",\"name\":\"Running Android app on device using Gradle - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"datePublished\":\"2014-07-27T22:50:58+00:00\",\"dateModified\":\"2014-07-28T18:43:37+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2145#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running Android app on device using Gradle\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Running Android app on device using Gradle - Denis Kutlubaev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.alwawee.ru\/?p=2145","og_locale":"en_US","og_type":"article","og_title":"Running Android app on device using Gradle - Denis Kutlubaev","og_description":"Here I will show you, how I managed to build and run an Android app via command line (Terminal, since I use Mac) using Gradle and how I start a resulting app on the device (Google Nexus 5 with Android 4.4.2) automatically. I had to solve two major problems to achieve this. The first problem [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=2145","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2014-07-27T22:50:58+00:00","article_modified_time":"2014-07-28T18:43:37+00:00","og_image":[{"url":"http:\/\/blog.alwawee.com\/?attachment_id=1982","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=2145#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=2145"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"Running Android app on device using Gradle","datePublished":"2014-07-27T22:50:58+00:00","dateModified":"2014-07-28T18:43:37+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=2145"},"wordCount":397,"commentCount":1,"keywords":["Android","Gradle"],"articleSection":["Android"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=2145#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=2145","url":"https:\/\/blog.alwawee.ru\/?p=2145","name":"Running Android app on device using Gradle - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"datePublished":"2014-07-27T22:50:58+00:00","dateModified":"2014-07-28T18:43:37+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=2145#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=2145"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=2145#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"Running Android app on device using Gradle"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2145"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2145\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}