Scala - Android App build fails - android

I am following the instructions to build Scala app for Android at:
scala-to-android
Basically, I installed Scala and changed the ant build.properties to point to Scala and changed build.xml to include build-scala.xml.
ant scala-compile
is successful, However,
ant debug
generates the following build errors:
scala-compile:
-shrink-if-test:
[echo] Checking if Scala libraries are installed on emulator or device...
[adb] BOOTCLASSPATH=/system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
-shrink-config:
[taskdef] Could not load definitions from resource scala/tools/ant/task.properties. It could not be found.
BUILD FAILED
/home/salil/Programs/android-projects/FirstScala/build-scala.xml:82: Problem: failed to create task or type invoked
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
I am a beginner in ant, Android and Scala. Any help would be appreciated. Thanks so much in advance!

I faced the same issue with android dev on Scala. Actually the build script looks for a file named task.properties which is located in scala/tools/ant/task.properties. This is packed inside the jar ant-invoked.jar. I hope you would have downloaded the android-sdk project zip archive from that site. Just copy the folder "configs" from the android-sdk root into your project root folder, this will work.
This is were it searches for the file in scala-build.xml
<!-- Project settings -->
property name="configs.dir" value="${basedir}/configs" />
<property name="ant-invoked.jar" value="${configs.dir}/ant/ant-invoked.jar" />
and the target shrink-config
<target name="-shrink-config"
description="Generate ProGuard configuration file">
<taskdef resource="scala/tools/ant/task.properties"
classpath="${ant-invoked.jar}" />

Currently, the most stable way to use Scala with android is to use the Simple Build Tool (SBT) and the Android Plugin
It basically "just works", handling all the steps for you and shrinking with Proguard.

Hi I have a blog here that documents steps to make scala work on android. It makes use of android ant process and sticks close to the android way. You can see the tutorial here
http://saadstechblog.blogspot.com/2011/09/scandroid-scala-android-tutorial.html. There is also a github project with all the configuration.

Related

Android Studio: Migrate complex build.xml to build.gradle

I have migrated my project from eclipse to android studio successfully and a default build.gradle file has been generated. The project builds correctly and I can deploy to debug etc.
The real problem though is building release APK files (from the command line) for which I used to have a custom ant-build (called via command line, not out of eclipse).
My custom build.xml imported the standard sdk build.xml file from the SDK folder via:
<import file="${sdk.dir}/tools/ant/build.xml" />
So all I had to do in my build.xml was to override targets or hook into them via "depends".
An example for an override:
<target name="-set-release-mode" depends="-set-mode-check">
<!--Here I rename my output apk files to something like: myapp-versionFromAndroidManifest.apk -->
</target
And an example for adding dependency:
<target name="-pre-build" depends="clean">
<!-- my custom code where I copy resource files, process command line arguments
use xpath to extract things like the version from the AndroidManifest.xml and
write them into custom xml files etc... -->
</target
So overall the whole affair was really simple using ant. But now when it comes to migrating to gradle I am at a total loss, how to accomplish the same that I previously did in ant, specifically:
For the build.xml there is a default build.xml that I imported in my ant build - does a standard build.gradle file exist somewhere so I can check out the defined tasks?
Is it possible to override gradle tasks and if yes: how?
I am pretty certain the depends="..." from ant can be mimicked in gradle but I have no idea how and that would also require an answer to question 1.
I googled a bunch of tutorials, also migration tutorials like (which unfortunately didn't address my issues):
http://keepsafe-engineering.tumblr.com/post/87818767721/migrating-android-app-from-ant-to-gradle
http://ryanharter.com/blog/2013/07/17/migrating-android-projects-to-gradle/
I also read this chapter from the gradle docs which didn't really help at all, because it does not answer question 1 or 2 or 3 for that matter:
http://www.gradle.org/docs/current/userguide/ant.html
The following gave some interesting pointers though:
http://toastdroid.com/2014/03/28/customizing-your-build-with-gradle/
I also tried simply copying the default build.xml from the sdk folder into my own build.xml and then simply importing that ant build file in gradle and executing the ant task that kicks of the build:
<target name="release"
depends="-set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build"
description="Builds the application in release mode.">
</target>
but I started running into problems that suggested this is not an option anymore, since the default build.xml started throwing errors, that seemed related to the SDK version. And I had to mess around a lot with the original sdk build.xml because of the new android studio project structure, so files were not where they were expected etc...
First, I would suggest you import the legacy project to android
studio. It will create the appropriate build.gradle script for you.
And then, you can list the task list by executing gradlew tasks at
the root of your project.
To depend on some tasks, you can use command such as init.dependsOn anotherTask.
Just for the record: I dumped the idea of using my previous ant-build and completely migrated to gradle. Most of the stuff I needed to do could be achieved just by the directory structure. You can find details on how I did that in my other question:
Android Studio: Gradle Product Flavors: Define custom properties
Now the second part was to call my java code that did some stuff I really did not want to migrate to groovy/gradle. Thus I figured out how to execute my java class (albeit I actually had to make a jar file out of it) from the gradle script:
Android Studio Gradle: Execute static Java Method (Migration from ANT to Gradle)
If anyone has questions, I'll be happy to try my best and answer them.

Apk location in New Android Studio

I started using new Android Studio and cant find the APK of the application in IDE,where it actually locates?
To help people who might search for answer to this same question, it is important to know what type of projects you are using in Studio.
Gradle
The default project type when creating new project, and the recommended one in general is Gradle.
For a new project called "Foo", the structure under the main folder will be
Foo/
settings.gradle
Foo/
build.gradle
build/
Where the internal "Foo" folder is the main module (this structure allows you to create more modules later on in the same structure without changes).
In this setup, the location of the generated APK will be under
Foo/Foo/build/apk/...
Note that each module can generate its own output, so the true output is more
Foo/*/build/apk/...
EDIT
On the newest version of the Android Studio location path for generated output is
Foo/*/build/outputs/apk/...
IntelliJ
If you are a user of IntelliJ before switching to Studio, and are importing your IntelliJ project directly, then nothing changed. The location of the output will be the same under:
out/production/...
Note: this is will become deprecated sometimes around 1.0
Eclipse
If you are importing Android Eclipse project directly, do not do this!
As soon as you have dependencies in your project (jars or Library Projects), this will not work and your project will not be properly setup.
If you have no dependencies, then the apk would be under the same location as you'd find it in Eclipse:
bin/...
However I cannot stress enough the importance of not doing this.
I am on Android Studio 0.6 and the apk was generated in
MyApp/myapp/build/outputs/apk/myapp-debug.apk
It included all libraries so I could share it.
Update on Android Studio 0.8.3 Beta. The apk is now in
MyApp/myapp/build/apk/myapp-debug.apk
Update on Android Studio 0.8.6 - 2.0. The apk is now in
MyApp/myapp/build/outputs/apk/myapp-debug.apk
There is really no reason to dig through paths; the IDE hands it to you (at least with version 1.5.1).
In the Build menu, select Build APK:
A dialog will appear:
If you are using a newer version of Android Studio, it might look like this:
Clicking the Show in Explorer or locate link, you will be presented with a file explorer positioned somewhere near wherever Android Studio put the APK file:
But in AS 3, when you click locate, it puts you at the app level. You need to go into the release folder to get your APK file.
In my case, I'm using Android Studio 1.0.2, I get my APK file from:
<myAndroidProject>/app/build/outputs/apk/app-debug.apk
If anyone would be missing his APK and couldn't find it in the locations stated in other answers (I found this question, since I couldn't find it either) it might just be in this folder (mine was)
<project folder>/target/classes/<appname>.apk
I also had a there this file:
<appname>.unaligned.apk
I am not perfectly sure, whether the apk is actually the full-blown apk, which should be generated, but I tried it on various devices (not only the target device, but also those which were supporting only the minimum SDK) and it worked.
Hope this will help someone.
It is Project_Location/app/build/outputs/apk for Gradle Project
Find apk using below step:-
Goto to your project folder.
Open project folder.
Open build folder.
Open output folder.
Open apk folder.
Now you see your apk.
hope it will help some body.
So the apk in Android studio is generated inside build folder of app module.
Correct path to apk would be \app\build\outputs\apk. I am using Android Studio Version 1.4.1. So apk could either be found at app/build/apk/ or \app\build\outputs\apk base on the version of Android studio you are using. Refer the below image
Also find more reference on these links.
Building and Running from Studio
Studio Project Overview
I'm using Android Studio and gradle.
It created the build/apk/<.apk> file only when I ran the project.
Press the following to run your project: Alt+u, u
Android Studio: 0.5.3
Gradle: 0.9.+
You can find the APK in:
YourProject\app\build\outputs\apk
The .apk file is located at [your project]\out\production\[your project name]
In the new Android Studio, the signed apk is placed directly in the folder of module for which the apk is built.
For example: For a Project ProjectA containing 2 modules Mod1 and Mod2, the apk files will be found in
/path-to-ProjectA/Mod1/Mod1.apk
/path-to-ProjectA/Mod2/Mod2.apk
Image for APK location in Android Studio
Location of apk in Android Studio:
AndroidStudioProjects/ProjectName/app/build/outputs/apk/app-debug-unaligned.apk
As of version 0.8.6 of Android Studio generating an APK file (signed and I believe unsigned, too) will be placed inside ProjectName/device/build/outputs/apk
For example, I am making something for Google Glass and my signed APK gets dropped in /Users/MyName/AndroidStudioProjects/HelloGlass/glass/build/outputs/apk
I got the .apk files in
parent_folder/out/production/projectname/projectname.apk
Build your project and get the apk from your_project\app\build\apk
You can find your apk file as follow:
yourproject>app>build>output>apk>yourproject.apk
The Android build system is the toolkit you use to build, test, run
and package your apps. The build system can run as an integrated tool
from the Android Studio menu and independently from the command line.
You can use the features of the build system to:
Customize, configure, and extend the build process.
Create multiple APKs for your app with different features using the
same project and modules.
The build process involves many tools and processes that generate intermediate files on the way to producing an .apk. If you are developing in Android Studio, the complete build process is done every time you run the Gradle build task for your project or modules.
The build process is very flexible so it's useful, however, to understand what is happening under the hood since much of the build process is configurable and extensible. The following diagram depicts the different tools and processes that are involved in a build:
Build a release version
You can now use the Build menu options to build the release version of your application for distribution.
The build generates an APK for each build variant: the app/build/apk/ (or app/build/outputs/apk) directory contains packages named app--.apk; for example, app-full-release.apk and app-demo-debug.apk.
Build output
The build generates an APK for each build variant in the app/build folder: the app/build/outputs/apk/ directory contains packages named app--.apk; for example, app-full-release.apk and app-demo-debug.apk.
Courtesy goes to Build System Overview
I am using Android Studio 3.0 canary 6.
To build apk,
Click to Build->Build APK(s).
After your apk is build, Go to:
C:\Users\your-pc-name\AndroidStudioProjects\your-app-name\app\build\outputs\apk\debug
If you have imported a Project from Eclipse and are using the new Android Studio
The directory
/bin
does exist (there maybe old binaries in here) however with the latest Android Studio update the actual current apk is stored in
/out/production
Add this in your module gradle file. Its not there in default project. Then u will surely find the APK in /build/outputs/apk/
buildTypes {
debug {
applicationIdSuffix ".debug"
}
}
open Event Log
find line: Module 'app': locate or analyze the APK.
click on locate link to open folder with apk file!
After all: "All built APKs are saved in project-name/module-name/build/outputs/apk/ Build your project LINK
Hint: If you can´t see the app-debug.apk in your debug folder, you have to click on BUILD --> Rebuild Project in Android Studio.
To create apk in android studio,go to build menu->build bundles/apk->build apk
it will make the apk file of your project.After this the apk will be available in your
project directory->app->build->outputs->apk->debug->app-debug.apk
Click on Build-Build Bundles/Apks-Build Apk.
A notification will which shows app location when you click on 'locate' on the notification.
If you have already done creating apk, goto : C:\Users\\AndroidStudioProjects\\app\build\outputs\apk\debug
For Gradle look here: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSetOutput.html.
"For example: Java plugin will use those dirs in calculating class paths and for jarring the content; IDEA and Eclipse plugins will put those folders on relevant classpath."
So its depend on plugin build in configs unless you don't define them explicit in config file.
Click the little gear icon in the project view and make sure "show excluded files" is checked. Otherwise, the IDE will hide output and several other important directories under $project/$module/build/.
Hello all above all answers are right you can find the apk through the path in android studio but there is exceptions you can't find the build/output
folder some times if you can't see it just go to
app--> app.iml file and find below line in it :-
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
--> after removing this line you can see the output folder its just the adding more information to above answers as per my experience :)
THANKS!~!
For Android Studio 2.0
C:\Users\UserName\AndroidStudioProjects\MyAppName\app\build\outputs\apk
Here
UserName is your computer user name and
MyAppName is your android app name
As of Android Studio 3.0 / Gradle Build Tools 3.0.0, APK artifacts can now be found in foo/bar/build/outputs/apk/flavorName/buildType with respect to your project name, foo, and your module name, bar. There is now a directory for each apk file sorted organized first by flavor (with respect to flavor dimensions) and then by build type.

library resolve to a path with no project.properties file

I'm having trouble building my project with Jenkins and referencing the Sherlock project library.
I can build the project with ant on my local system. The problem seems to be referencing the Sherlock library on the build server.
I pass an environment variable to ant with the relative path to the Sherlock library project:
android.library.reference.1=../../buildlibraries/androidlibraries/sherlock/library
I'm getting this error.
**BUILD FAILED**
/SDK/android-sdk-macosx/tools/ant/build.xml:595:
The following error occurred while executing this line:
/SDK/android-sdk-macosx/tools/ant/build.xml:571:
../../buildlibraries/androidlibraries/sherlock/library resolve to a path with
no project.properties file for project /Users/Jenkins/buildlibraries/androidlibraries/sherlock/library
I checked and a project.properties file does exist at that location.
It has these properties:
android.library=true
# Project target.
target=android-14
I had the same thing happen to me just now. I use both a Windows and Mac to develop with. I watne d to test my project on both platforms. It built just fine on my Windows machine, but broke on my Mac. When I looked at my project.properties in my Android application (not library projects) on the Mac, I saw that my library projects were referenced this way:
android.library.reference.1=LibraryProjects\\my_lib_project
I changed it to the line below, and it worked just fine!
android.library.reference.1=LibraryProjects/my_lib_project
I solved the issue by editing and checking in the project.properties file with the same property: android.library.reference.1=../../buildlibraries/androidlibraries/sherlock/library
I'm not sure why it works. Why would ant care if the property is passed in by Jenkins vs. declared in the project's property file?
Now I have two paths in my project.properties file: one for a local build and one for the build on Jenkins.
I had similar issue with error ../google-play-services_lib resolve to a path with no project.properties file for project. It has to work in Jenkins CI (Cloudbees), so no manual project.properties editing.
My solution was to replace android update lib-project --path ... with ugly but working echo "android.library.reference.1=../../../..$ANDROID_HOME/extras/google/google_play_services/libproject/google-play-services_lib" >> project.properties in Jenkins shell command.
I had this problem because I hadn't downloaded the google play services package using the android tool. When I checked my android sdk directory ($ANDROID_HOME) there was no "$ANDROID_HOME/extras/google" folder.
I fixed this by running android and downloading "Google Play services" found in the extras section.

Building Android library with Eclipse vs Ant

I have a simple Android library project, which contains network calls functionality only. It doesn't need to inherit any XML/resources etc… to calling application. When I build this project using Eclipse IDE (right click on project and click on Build Project), it generates a JAR under bin/libproject.jar. I can simply drop this file to any project's build path and it works fine.
Now, I want to implement continuous integration for my library. That means, I need some command-line way to achieve the same (building jar, when I build the project using ant). Ant builds the project differently. It creates classes.jar in bin/ folder, which is not the same as as libproject.jar.
I believe Eclipse's Build Project (ADT rev-21) is doing something magical to build this complete JAR for my library project (this is more like a java project like JAR).
Do you know how can I achieve the same using command line?
im using eclipse 4.3 w/ ant and with sdk tools 21.1
IMO - they recently changed the sdk regarding lib dependencies.
http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
see the above link.
my example lib dependency(transitive) as follows:
ABS <== SlidingMenu <== MyProject
so, in SM.project.properties...
android.library.reference.1=../../src/ABS/library
and, in MP.project.properties ...
android.library.reference.1=../../src/SlidingMenu/library
The ant build, run on proj=SM using either eclipse internal, ant build tools OR ant on CLI in a terminal session outside eclipse
does following:
[javac] Note: Recompile with -Xlint:deprecation for details.
[echo] Creating library output jar file...
[jar] Building jar: /home/rob/src/tools/ActionBarSherlock-4.2.0/library/bin/classes.jar
and ant build, run on proj=MP does the following:
Setting project property: out.library.jar.file -> /home/rob/src/SlidingMenu/library/bin/classes.jar
..
[jar] Building jar: /home/rob/src/SlidingMenu/library/bin/classes.jar
IMO - you should focus on 2 things :
get the lib reference correct in the file=project.properties of the dependent.
double check in eclipse the project /properties/ java build path / order and export
read the link as it contains multiple , specific NOTEs relating to 'order export'...
When you build the dependent project in ant , it should trigger internally, builds of the other projects. I think that is controlled in the build path of the dependent project.
An additional NOTE on debugging - i could not debug directly from the project explorer because the launcher did not like the "classes.jar" for the 2 , dependent projects. Debug insisted on there being jars with names "${project-name}.jar" in the ./bin directory of each library. But ant assigns "classes.jar" as shown above.
So, to debug, i used the alternate method of DDMS tab in eclipse w/ the app already running. then u find the process and attach the debugger.

Build Android Library Project With Ant

I am having trouble building my Android library project with ant. When I try to run ant release, it says Target "release" does not exist in the project "MyProject".
I then assumed that perhaps libraries do not get build with release/debug, so I started using ant compile, which seems to work. I then zip the folder manually using java's zip utility and rename it to .apk. I am guessing this is the wrong way to do this.
Can anyone show me how to build an Android library project using ant?
I then assumed that perhaps libraries do not get build with release/debug
Correct.
I am guessing this is the wrong way to do this.
Also correct.
Can anyone show me how to build an Android library project using ant?
You typically do not build an Android library project. You build other projects that reference the Android library project. Creating projects that reference the library project, for use with Ant, is covered in the Android documentation. More information about the role of Android library projects can also be found in the Android documentation.
I had the same trouble with a target "nodeps" that was not known by Ant when building a project that was referencing a library. I added a fake target "nodeps", then I get the target "release" unknown. Wrong way.
Solution : in my referenced library directory, I run the command android update project -p . that created the build.xml compatible with Ant build.

Categories

Resources