I have a Xamarin project am looking to build a Android apk using mdtool, and the command line.
Here is the setup :
I have a mac mini - Xamarin Studio installed on it, I have the solution which build no problem.
Now from the command line this is what I an trying to do
#REM Traverse to the folder which holds the .sln file
cd One/Xamarin/Android/OneAndroid
#REM start the build using mdtool
'/Applications/Xamarin Studio.app/Contents/MacOS/mdtool' -v build OneAndroid.sln
The above completes the build for me , however I do not get an apk file.
Could someone share with me which option needs to be added onto mdtool to generate an apk file?
Thanks
Rajesh
I understand I maybe missing some parameters for mdtool
Use XBuild to compile the APK, for example:
xbuild MyXamarinAndroidApplication.csproj /p:Configuration=Release /t:SignAndroidPackage
This will compile the project in release mode and generate a signed and unsigned APK. If you just want an unsigned APK:
xbuild MyXamarinAndroidApplication.csproj /p:Configuration=Release /t:PackageForAndroid
It's worth noting that you have to specify a .csproj, not a .sln. If you give it a solution file, you'll get an error complaining that it can't find the "SignAndroidPackage" target.
Check out the build process documentation from Xamarin: http://docs.xamarin.com/guides/android/advanced_topics/build_process/offline.pdf
Related
I'm using Android Studio 2.3 beta 3. I put message(AUTHOR_WARNING "Hello CMake, hello Android") In my CMakeLists.txt
But I saw this message only few times when rebuilding project in Android Studio. In most cases there's no "Hello CMake, hello Android" string in Gradle Console after build finishes. I've tried resync gradle and clean/rebuild project, still no expected output.
I have some problems with my build (I think it's incorrect paths) so my goal - to print CMake variables in compile time to better understand what is actually going on.
Inside the project tree, you can find the log with all the cmake output inside the folder of each generated architecture. The relative path to the file should be something like:
[project folder]/app/.externalNativeBuild/cmake/debug/arm64-v8a/cmake_build_output.txt
Here you can see all the MESSAGE calls of the cmake scripts.
my android studio cmake output:
compile detail:
.cxx/cmake/debug/arm64-v8a/compile_commands.json
cmake output:
.cxx/cmake/debug/arm64-v8a/build_output.txt
CMake messages are only at generation time (when CMake is used to generate your project / Makefile).
One way to get CMake to generate is to go to retrieve the build folder and the CMakeCache.txt file in it, and then:
Retrieve the path to your cmake executable, by reading the CMakeCache.txt file and checking the value of the CMAKE_COMMAND variable
Open a command prompt in CMakeCache.txt directory
Run: <path_to_cmake_found_at_point_1> .
Note: The build folder should have a CMakeCache.txt file. The above will not work unless it does.
On my rig I found the logs in <module name>/build/intermediates/cxx/<cmake build type>/<hash>/meta/<ABI>/cmake_server_log.txt -- C++ programming for Android just keeps getting more convenient all the time :\
My rig:
Android Studio Arctic Fox 2020.3.1 Patch 3
AGP 7.0.2
Gradle 7.2.0
NDK 21.4.7075529
CMake 3.10.2
Windows 10 (hopefully host OS doesn't matter)
So I tried run, make, assemble, from android studio on a vanilla hello world app (it's the app that it creates from the default file -> new project and I can't find the unsigned APK in the MyApplication/build folder. I can generate a signed apk going through the build menu but I can't seem to find the auto generated debug apk.
I also tried following some instructions on going through the project structure menu but I can't find a plus button that adds an artifact.
If your project has modules (e.g., an app/) module, APKs go in the module. So, I would look in app/build/outputs/apk/ (again, assuming that you have an app/ module).
You should build apk by gradle.
1.Enter the root directory of your project and command ./gradlew -v to download gradle.
![./gradlew -v][1]
[1]: http://i.stack.imgur.com/iMbGO.jpg if you download successfully, you'll see this formation.
2.command ./gradlew clean to download dependencies of gradle.
![./gradlew clean][1]
[1]: http://i.stack.imgur.com/WlWQR.jpg if successfully, you'll see this formation.
3.command ./gradlew build to build and generate apks.
Enter [Your-project]/app/build/outputs/apk, you will see app-debug.apk, app-debug-unaligned.apk, app-release-unsigned.apk.
You can use the option Build -> Analyse Apk and you can find the path of your apk
I've created a android project using eclipse. But I needs to do that same using command line. So, I use below command
> android update project --path .
> ant clean debug
Using above command its created-- Welcome-debug.apk and WelCome-debug-unaligned.apk
I also write the ant.properties file below-
key.store=./mykey.keystore
key.alias=MA
key.store.password=mypassword
key.alias.password=mypassword
now when I tried to build release version-
> ant relase
Unfortunately its not creating any release file. How do i create the release version using command line.
Expecting your response.
Thanks,
Pijman
You have a typo: it should be ant release.
You don't need to do anything specific. ant clean release should do the trick. However, note the clean target: ant is lazy and is trying to skip as much of the work as possible - thus if you do not clean it will not recreate the class files and you will actually pack an apk featuring the debug compiled files.
I setup Emma and it used to work for me. Then we had source code changes and now it doesn't generate coverage.ec at all. It does generate coverage.em.
Near the end of testing, it has error messages:
[exec] INSTRUMENTATION_CODE: 0
[echo] Downloading coverage file into project directory...
[exec] remote object '/sdcard/coverage.ec' does not exist
BUILD FAILED
/var/lib/jenkins/android-sdk-linux_x86/tools/ant/build.xml:1056: exec returned: 1.
Line 1056 of build.xml is
"{adb}" failonerror="true".
I see that I do have coverage.em on the desktop, which means my code are instrumented.
the command I use under the \test is
ant emma debug install test
This worked for me before. Running code coverage always crashes for me, usually near the end of the unit test, but it'd always get me some coverage. Now it crashes out and doesn't produce coverage.em.
I also tried to access /sdcard/ and it's perfectly accessible and writable.
This has blocked me for days, any input would be much appreciated. I am also new to all this Android, Ant and Emma, so thanks!!
Update:
I just cleaned up the environment and ran the command again.Now coverage.em is no longer generated either. Which tells me the source code are not instrumented. But the command I used above should instrument project, its test project, install and start test. I didn't change emma def in build.xml except to change the coverage.ec location to /sdcard/coverage.ec. This is because by default it goes to /data/data, and I don't have permission to access data/data on this phone
I am using r15 of Android SDK, and the default build.xml. I only changed the path to coverage.ec to /sdcard/coverage.ec. To run instrumentation
Go to main_project
$andriod update project -p .
Go to main_prject\test
$android update project -m ../ -p .
To start code code
$ant emma debug install test
It generated main_project-instrumented.apk and test_project-debug.apk. Both are installed and I can see it executes testing.
You have to make a test project with the android command line tools first.
Create Project & Test Project
Assuming your project is stored in D:\AndroidProject and your programming against android API level 8. First you use this command to create the project:
android update project --path ./ --name blabla~ --target android-8 --subprojects
Then create an folder for the test project and navigate into that folder:
mkdir Android_test
cd Android_test
Then create the android test project with the below command
android create test-project --main ../AndroidProject --path ./
Ant building with emma coverage report (with root)
Execute this command (from jenkins select and build step) to get a build done with emma reporting:
ant emma debug install test
Caution : For this to work you have to connect rooted device or emulator, then execute ant command!
Change Build xml file (so no root is required)
If you don't want to root your device an alternative solution is to alter the location of these coverage reports. For this you should modify the build.xml file.
(you should googling about that for more information, briefly explained here)
Open the build.xml -> find the location where the coverage.ec file is stored. In most cases this will be stored in /data/data/com.example.Android/coverage.ec
The problem here is that the /data/data/~~~ path is protected (hence the required root).
anyway~ you can get a coverage.html file in your test project folder/bin. The next steps explain how to change this to save this file on the /sdcardinstead!
You can open your build.xml file and at the last line ~ you can find the command import ~~~ build.xml which means that your build.xml file will import anoother build.xml file.
The other build.xml file is part of the android SDK and is located at ${Android-sdk}/tools/ant/build.xml.
Required changes for build.xml file
We can't change this file (without getting into trouble) so instead copy the complete file to an alternative location or directly into your projects build.xml file.
Don't forget to adapt or change the import statement in your build.xml file whatever you choose to do.
This is what you need to change in that new build.xml file:
Erase the import= ~~build.xml
Erase the first line which is xml=ejkwjkw?e jw ""project = "android_rule" ~~ ~blabla)
and last line /project
update address to /sdcard/coverage.ec
Then, you can get coverage.ec file~
I ran into this issue after updating my SDK to r16: Emma code coverage not working in r15 of tools
and this fixed it for me:
ant all clean emma debug install test
But I am unsure if you have the same problem.
I don't have permission to access data/data on this phone
Is it a non-rooted device? Note that the build says:
WARNING: Code Coverage is currently only supported on the emulator and rooted devices.
Maybe you can't work around this limitation by just changing the location of the coverage file. Does it work on a virtual device?
anybody tell me, building apk using ant script
Check the android developers documentation in the Building and Running from the Command Line topic. Assumed you created your project with the android tool it should be:
ant release
The documentation also describes the "eclipse with ADT" way
If you first set up the project with eclipse than try to create a new temp project with the android create project command line command and take the build.xml (and build.properties + local.properties) from the new project for your existing one.
http://androidyou.blogspot.com/2012/12/android-project-ant-build-and-put.html
add one target to get the version, using the regular expression to extract it from the manifest.xml
then add this as a dependency to the release target