Adding assets to Android Project, Visual Studio 2015 CTP - android

I am attempting to add assets to an android project, using Visual Studio 2015 CTP. When I add files to ProjectName.Packaging/res the build fails with the error:
1> -package-resources:
1> [aapt] Found Deleted Target File
1> [aapt] Creating full resource package...
1> [aapt] invalid resource directory name: C:\ProjectName\ARM\Release\Package\res image.png
1>
1> BUILD FAILED
1> C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:932: The following error occurred while executing this line:
1> C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:950: null returned: 1
1>
1> Total time: 0 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\AndroidPackaging\Android.Common.targets(280,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Apps\apache-ant-1.9.3\\bin\ant.bat" debug -Dout.final.file="C:\ProjectName\ARM\Release\ProjectName.Packaging.apk"" exited with code 1.
Please advise. Thanks.

Ok, I was able to answer my question. Right click ProjectName.Packages -> Add -> New Folder and name it assets. Right click assets -> Add -> Existing Item -> select the asset you wish to add.
If the error persists, clean project AND manually delete the build folder from C:\ProjectName\ARM\Release or whatever. Rebuild.

The file name of your resources can't contain spaces, use a _ instead

Related

Android - Copy build output to another folder with Gradle

I am trying to build my React Native Android app on Visual Studio App Center and I get this error:
Task : Shell script
Description : Run a shell script using Bash
Version : 2.165.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/shell-script
==============================================================================
[command]/bin/bash /Users/runner/runners/2.165.2/scripts/android-postprocess.sh /Users/runner/runners/2.165.2/work/1/s/mobile/android/app/app/build/outputs/apk
Removing all ABI or density dependent APKs…
find: /Users/runner/runners/2.165.2/work/1/s/mobile/android/app/app/build/outputs/apk: No such file or directory
find: /Users/runner/runners/2.165.2/work/1/s/mobile/android/app/app/build/outputs/apk: No such file or directory
find: /Users/runner/runners/2.165.2/work/1/s/mobile/android/app/app/build/outputs/apk: No such file or directory
Found 0 APK file(s)
Found 0 unaligned APK file(s)
find: /Users/runner/runners/2.165.2/work/1/s/mobile/android/app/app/build/outputs/apk: No such file or directory
/Users/runner/runners/2.165.2/scripts/android-postprocess.sh: line 36: pushd: /Users/runner/runners/2.165.2/work/1/s/mobile/android/app/app/build/outputs/apk/..: No such file or directory
/Users/runner/runners/2.165.2/scripts/android-postprocess.sh: line 43: popd: directory stack empty
##[error]The process '/bin/bash' failed with exit code 1
##[error]Bash failed with error: The process '/bin/bash' failed with exit code 1
##[section]Finishing: Android Postprocess
##[section]Starting: Post Build Script
It's incorrectly looking for my APK in the app/app/build/... instead of app/build/...So I want to copy the files to app/app/build/.. so it finds them there.
I can't copy the files with a post-build script because it runs after the script that throws the error.
Is it possible to somehow achieve copying with Gradle? Or maybe have multiple build paths? Or some other solution?
The problem was that I had gradlew, gradlew.bat and gradle folder in my appmodule folder. I must have mistakenly opened the app folder alone in Android Studio and synced the project.
I solved it by creating a fresh React Native project.

Binding .AAR Library in Xamarin.Android with javadoc doesn't adopt parameter names

I've been trying to include the javadoc to a .aar library so I don't have to manually edit every method parameter name in the MetaData.xml file.
So far I've done everything suggested in this thread but I still can't get it to work.
I generated the javadoc like so:
javadoc -subpackages at -notree -noindex -nohelp -nonavbar -d javadoc
In my build output, the JarToXml task looks like this:
1>Task "JarToXml"
1> JarToXml Task
1> JavaOptions:
1> JavaMaximumHeapSize:
1> AndroidSdkDirectory: C:\Program Files (x86)\Android\android-sdk\
1> AndroidApiLevel: 17
1> MonoAndroidToolsDirectory: C:\Program Files (x86)\MSBuild\Xamarin\Android
1> JavaSdkDirectory: C:\Program Files (x86)\Java\jdk1.7.0_71\
1> OutputFile: obj\Release\api.xml
1> DroidDocPaths:
1> JavaDocPaths: JavaDocs\javadoc\
1> Java7DocPaths: JavaDocs\javadoc\
1> JavaDocs: {0}
1> JavaDocs\javadoc\index.html
1> AndroidApiLevel: 17
1> LibraryProjectJars:
1> obj\Release\__library_projects__\*.jar
1> SourceJars:
1> obj\Release\library_project_jars\\classes.jar
1> ReferenceJars:
1> C:\Users\Peter\AppData\Local\Xamarin\Android.Support.v4\21.0.3\embedded\classes.jar
1> C:\Users\Peter\AppData\Local\Xamarin\Android.Support.v4\21.0.3\embedded\libs\internal_impl-21.0.3.jar
I'm suspicious of the build output of the "BuildDocumentation" task, because on the one hand, it adds members with p0, p1, etc. as parameter names, and on the other hand, it doesn't find the right javadoc members.
1> Member Added: protected virtual void SetLevelsForAutoFlash (int p0, int p1, int p2, int p3);
1> Member Added: public virtual void SetVibrateOnResult (bool p0);
....
1> Updating member anchor: hasNewImage()
1> javadoc-to-mdoc: Could not find JavaDoc for member: hasNewImage().
1> Updating member anchor: getNewImage()
1> javadoc-to-mdoc: Could not find JavaDoc for member: getNewImage().
....
I've set up a property for both JavaDocPaths and Java7DocPaths in my .csproject just to be sure, and I added the javadoc to a subfolder JavaDocs/javadoc in my project, where I set the build action of index.html to JavaDocIndex.
<PropertyGroup>
<Java7DocPaths>JavaDocs\javadoc\</Java7DocPaths>
</PropertyGroup>
<PropertyGroup>
<JavaDocPaths>JavaDocs\javadoc\</JavaDocPaths>
</PropertyGroup>
I'm using Visual Studio 2013 btw. What am I missing here?
Cheers, EtePetete
(PS: I've tried to post this issue twice now in the Xamarin forum, but they seem to reject my question without any reason)

Cannot build signed android package through visual studio cordova

I am trying to build a signed release package for my Android application using Visual Studio 2015 Cordova Tools.
I am using Cordova 5.1.1, which requires that I supply the build process with a build.json file, telling the application where the keystore are and what password is using.
However when I add the build.json file, I am not able to make a successful build to release.
I followed this guide: https://github.com/Microsoft/cordova-docs/tree/master/tutorial-package-publish#android
And got this error (with path edited out):
1> ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk (TaskId:11)
1> JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_55 (TaskId:11)
1> \build.json (TaskId:11)
1> Reading build config file: \build.json (TaskId:11)
1> \platforms\android\cordova\node_modules\q\q.js:126 (TaskId:11)
1> throw e; (TaskId:11)
1> ^ (TaskId:11)
1> SyntaxError: Unexpected token  (TaskId:11)
1> at Object.parse (native) (TaskId:11)
1> at parseOpts (\platforms\android\cordova\lib\build.js:475:27) (TaskId:11)
1> at Object.module.exports.run (\platforms\android\cordova\lib\build.js:529:16) (TaskId:11)
1> at \platforms\android\cordova\build:36:22 (TaskId:11)
1> at _fulfilled (\platforms\android\cordova\node_modules\q\q.js:798:54) (TaskId:11)
1> at self.promiseDispatch.done (\platforms\android\cordova\node_modules\q\q.js:827:30) (TaskId:11)
1> at Promise.promise.promiseDispatch (\platforms\android\cordova\node_modules\q\q.js:760:13) (TaskId:11)
1> at \platforms\android\cordova\node_modules\q\q.js:574:44 (TaskId:11)
1> at flush (\platforms\android\cordova\node_modules\q\q.js:108:17) (TaskId:11)
1> at process._tickCallback (node.js:355:11) (TaskId:11)
1> Command finished with error code 1: cmd /s /c ""\platforms\android\cordova\build.bat" --release "--buildConfig=\build.json"" (TaskId:11)
1>ERROR building one of the platforms : error : cmd: Command failed with exit code 1
1> You may not have the required environment or OS to build this project (TaskId:11)
1>MDAVSCLI : error : cmd: Command failed with exit code 1
1>Done executing task "MdaVsCli" -- FAILED. (TaskId:11)
What am I doing wrong? It seems like it cant parse the JSON?
This issue is caused because the default build.json has a BOM that the NodeJS JSON parser doesn't like. You can fix this in a number of ways, but the simplest is to open the file using Visual Studio's Binary editor.
Right-click build.json, select "Open With...", then choose the "Binary Editor" from the list. You should see something like this:
Select the first three bytes as in the screenshot, and delete them, then save the file. The parser should now accept the file, and signing will work as expected.
I tried this approach as well following the same documentation. and getting exactly the same error.
After looking at the android build documentation, i.e the Signing Your App Manually
I realised that it should be possible to build the application in release mode (i.e an apk that is unsigned is generated 1st), so i removed build.json and tried this, and I got errors. I did a few google searches and came up this [post][2].
[2]: Error when running cordova build –release android In summary this my advice.
Remove the build.json file.
Clean the solution set it to debug mode and make sure you can a successful build.
Clean the solution set it to release mode.
Go to your application directory find platforms\android you'll see build.gradle.
Create a new file build-extras.gradle, i got this suggestion from one of the on the [post][2]
[2]: Error when running cordova build –release android you don't want to be editing the auto generated build.gradle file.
In your build-extras.gradle put android { lintOptions {
disable MissingTranslation
} }
Now go and build your solution, it should work and you'll get an unsigned apk i.e android-release-unsigned.apk in your bin\Android\release folder.
Sign your apk manually by following android build - signing your app manually steps
Additionally to the reason #dlev posted I found another reason that could cause this:
I was using a path containing folder names foo\bar. This worked before, but it seems now (I have no idea if node, cordova or whatever got updated) this doesn't work any more and you have to escape the directory seperator: foo\\bar.
After adding this, I can build my project again.
Another hack is to leverage android's build system. In platforms\android put your keystore file and inside your build-extras.gradle. the following
android {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
signingConfigs {
release {
keyAlias = ""
keyPassword = "yourpassword" // And these must be set to non-empty in order to have the signing step added to the task graph.
storeFile = file("yourfile.keystore")
storePassword = "yourpassword"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
If you want to create the illusion of full automation then you could use a gulp task "a pre-build step" to copy your keystore file and build-extras gradle file to platforms\android from wherever you have them.

Unable to build Cordova project in Visual Studio

I'm using Visual Studio 2013 and the Cordova CTP 1.1. When I try to build the project, I get the following cryptic error (line breaks added for readability):
Error 22
The command ""C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\vs-cli"
prepare --platform Android --configuration Debug
--projectDir . --projectName "servermon"" exited with code 8.
C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda-targets\Microsoft.MDA.targets 115 5 servermon
I've tried the solutions from this question as well as this question, and this doesn't appear to solve the issue. My system path appears to have everything relevant in it:
C:\Program Files\Java\jdk1.7.0_60\bin
C:\Users\Nathan\AppData\Local\Android\android-sdk\tools
C:\Users\Nathan\AppData\Local\Android\android-sdk\platform-tools
C:\apache-ant-1.9.3\bin
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
C:\Program Files (x86)\Windows Live\Shared
C:\Program Files\Microsoft\Web Platform Installer\
C:\Program Files (x86)\nodejs\
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
I've also opened up the SDK manager and made sure to get the latest (Rev 19) build tools. The system has been restarted more than once and I'm still not able to build. Does anyone have any ideas on how to fix this build issue?
Edit: Here is a screenshot of my SDK Manager
Edit2: Here is the build output
1>------ Build started: Project: servermon, Configuration: Debug Android ------
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\TypeScript\Microsoft.TypeScript.targets(90,5): warning : The TypeScript Compiler was given no files for compilation, so it will skip compiling.
1> Your environment has been set up for using Node.js 0.10.26 (ia32) and npm.
1> ------ Ensuring correct global installation of package from source package directory: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\al3uox1v.u2n\packages\vs-mda
1> ------ Build settings:
1> ------ buildCommand: prepare
1> ------ platform: Android
1> ------ cordovaPlatform: android
1> ------ configuration: Debug
1> ------ cordovaConfiguration: Debug
1> ------ projectName: servermon
1> ------ projectSourceDir: C:\Users\Nathan\Documents\CordovaTest\cordovatest\cordovatest
1> ------ App dir C:\Users\Nathan\Documents\CordovaTest\cordovatest\cordovatest\bld\Debug already exists
1> ------ Copying app files to www
1> ------ Done copying app files to www
1> ------ Copying res files
1> ------ Done copying res files
1> ------ Platform android already exists
1> ------ Certificate copy from C:\Users\Nathan\Documents\CordovaTest\cordovatest\cordovatest\res\cert\android to platforms\android
1> ------ Done copying certificate files to platforms\android
1>
1> C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:126
1> throw e;
1> ^
1> CordovaError: The provided path "C:\Users\Nathan\Documents\CordovaTest\cordovatest\cordovatest\bld\Debug\platforms\android" is not an Android project.
1> at Object.android_parser (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\src\metadata\android_parser.js:37:15)
1> at C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\src\prepare.js:51:23
1> at Array.map (native)
1> at Object.prepare (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\src\prepare.js:49:35)
1> at preparePlatform (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\app.js:322:24)
1> at _fulfilled (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:787:54)
1> at self.promiseDispatch.done (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:816:30)
1> at Promise.promise.promiseDispatch (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:749:13)
1> at C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:557:44
1> at flush (C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:108:17)
1>C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda-targets\Microsoft.MDA.targets(115,5): error MSB3073: The command ""C:\Users\Nathan\AppData\Roaming\npm\node_modules\vs-mda\vs-cli" prepare --platform Android --configuration Debug --projectDir . --projectName "servermon"" exited with code 8.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It seems the Android template that was downloaded by Cordova is "corrupted".
To fix this:
Try deleting the cached android platform in your user directory:
C:\users\<username>\.cordova\android\*
Then, clean and build the Solution in Visual Studio. Or to be really sure, delete the ‘bld’ directory inside the project folder.
This should force Cordova to re-download the Android template and fix the issue.
for me I just deleted the bld folder and eveerything has become right
Some time visual studio catch creates problem, clear the cache.
Choose Tools, Options, Tools for Apache Cordova, and then choose
Cordova Tools.
Choose Clear Cordova Cache.
Close and re-open your project.
Choose Build, Clean Solution.

phonegap run android fails with "...\classes.dex does not exist"

Just installed phonegap on windows 7 64bit and have run :
phonegap create testpg
cd testpg
phonegap -V run andoid
The last command aborts with the following error message:
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] compiling Android...
[phonegap] Generating config.xml from defaults for platform "android"
[phonegap] Compiling app on platform "android" via command "cmd" /c D:\Dev\projects\testpg\platforms\android\cordova\build
[error] An error occurred while building the android project.Error executing "ant debug -f "D:\Dev\projects\testpg\platforms\android\build.xml"":
BUILD FAILED
D:\Dev\sdk\tools\ant\build.xml:962: The following error occurred while executing this line:
D:\Dev\sdk\tools\ant\build.xml:973: The following error occurred while executing this line:
D:\Dev\sdk\tools\ant\build.xml:313: com.android.sdklib.build.ApkCreationException: java.io.FileNotFoundException: D:\Dev\projects\testpg\platforms\android\bin\classes.dex does not exist
Does anyone knows what's going on and how i can fix this?
Thanks in advance!
PS. i tried and run "ant debug -f "D:\Dev\projects\testpg\platforms\android\build.xml"":
and it gives quite verbose output. here is the last part :
......................
-dex:
[dex] input: D:\Dev\projects\testpg\platforms\android\bin\classes
[dex] input: D:\Dev\projects\testpg\platforms\android\CordovaLib\bin\classes.jar
[dex] Pre-Dexing D:\Dev\projects\testpg\platforms\android\CordovaLib\bin\classes.jar -> classes-529c048069aff9da86f06bdc712f5b33.jar
[dex] Found Deleted Target File
[dex] Converting compiled files and external libraries into D:\Dev\projects\testpg\platforms\android\bin\classes.dex...
-crunch:
[crunch] Crunching PNG Files in source dir: D:\Dev\projects\testpg\platforms\android\res
[crunch] To destination dir: D:\Dev\projects\testpg\platforms\android\bin\res
[crunch] Crunched 0 PNG files to update cache
-package-resources:
[aapt] Creating full resource package...
[aapt] Warning: AndroidManifest.xml already defines debuggable (in http://schemas.android.com/apk/res/an...); using existing value in
manifest.
-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating HelloWorld-debug-unaligned.apk and signing it with a debug key...
BUILD FAILED
D:\Dev\sdk\tools\ant\build.xml:962: The following error occurred while executing this line:
D:\Dev\sdk\tools\ant\build.xml:973: The following error occurred while executing this line:
D:\Dev\sdk\tools\ant\build.xml:313: com.android.sdklib.build.ApkCreationException: java.io.FileNotFoundException: D:\Dev\projects\testpg\platforms\android\bin\classes.dex does not exist
....................
interestingly there is a line that says "[dex] Converting compiled files and external libraries into D:\Dev\projects\testpg\platforms\android\bin\classes.dex..." and yet in the end build fails with "java.io.FileNotFoundException: D:\Dev\projects\testpg\platforms\android\bin\classes.dex does not exist"
Try rebuilding the project..
Go to Build > Make Project (ctrl + f9).
and run again
it worked for me..

Categories

Resources