I'm trying to make a bundle for Felix on Android which may take photos regularly.
All the code compiles well and it can be resolved by Felix, but when I try to start it, I get an exception (java.lang.VerifyError) and this trace in logcat :
I/dalvikvm( 738): Failed resolving Lbarcode/android/CameraHandler; interface 1 'Landroid/hardware/Camera$PictureCallback;'
W/dalvikvm( 738): Link of class 'Lbarcode/android/CameraHandler;' failed
E/dalvikvm( 738): ERROR: defineClass(0x40093110, barcode.android.CameraHandler, 0x400c93b8, 0, 1769, 0x40204708)
The CameraHandler class opens a Camera object, and implements PictureCallback and AutoFocusCallback.
The .jar file has been 'dexed', via a simple 'dx --dex --output=classes.dex ... && aapt add ... classes.dex'.
I don't know why this error raise, so if someone has a solution...
Thanks
It appears that you've omitted some necessary classes as arguments to dx.
You'll have more success if you use either Android's Eclipse plug-in or the create project action in the android commandline tool. Each of these take care of running the right tools in the right order to build an Android apk to spec.
$ ~/android-sdk/tools/android --help
Usage:
android [global options] action [action options]
...
Action "create project":
Creates a new Android Project.
Options:
-n --name Project name
-t --target Target id of the new project [required]
-p --path Location path of new project [required]
-k --package Package name [required]
-a --activity Activity name [required]
Related
I am trying to build OpenCV to include OpenCV contrib modules which is in a repository. I am following the instructions in this link, but i could not understand the cmd commands which is i mentioned in the section titled "cmd commands" as follows.
cmd commands:
$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules
<opencv_source_directory>
$ make -j5
here are my attempts to get the cmd commands as mentioned above running:
1-concerning the opencv_build_directory: i just created it by myself and named it 'build' as shown in the image in the section titled "OpenCV3.0.0 source"
2-concerning the opencv_source_directory: i think it should be "OpenCV-android-sdk" as shown in the image section titled "OpenCV3.0.0 source"
3- for the cmd command '$ cd ' i set it as follows:
c:\xxxx\libs\OpenCV-3.0.0-android-sdk-1\OpenCV-android-sdk\build>
4- for the cmd command '$ cmake -DOPENCV_EXTRA_MODULES_PATH=/modules' iset it as follows:
cmake -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib-master/modules OpenCV-
android-sdk
the entire command i type in the cmd is:
c:\xxxx\libs\OpenCV-3.0.0-android-sdk-1\OpenCV-android-
sdk\build>cmake -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib-
master/modules OpenCV-android-sdk
but after running it, i get:
CMake Error: The source directory "C:/xxxx/libs/OpenCV-3.0.0-
android-sdk-1/OpenCV-android-sdk/build/OpenCV-android-sdk" does not
exist.
Specify --help for usage, or press the help button on the CMake GUI.
please help me to build the path correctly as stated in the linke mentioned
note:
I am trying to install opencv contrib modules on android through android Studio
OpenCV3.0.0 source
OpenCV-contrib source:
I'm trying to build a standard "Hello, World!" command-line executable for Android. The executable is to be run via adb shell.
0. The Go (Golang) Source
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, world!")
}
1A. The Build Command
$ CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=7 go build .
1B. The Output (Line Breaks Rearranged to Prevent Scrollbars)
# github.com/asukakenji/cross
warning: unable to find runtime/cgo.a
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file
/var/folders/dd/6k6vkzbd6d5803xj9zkjdhmh0000gn/T/go-link-150305609/go.o,
file was built for unsupported file format
( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
which is not the architecture being linked (x86_64):
/var/folders/dd/6k6vkzbd6d5803xj9zkjdhmh0000gn/T/go-link-150305609/go.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
1C. The Build Command, Again
The following command gives the same result:
$ env CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=7 go build .
2. The Build Command (Verbose)
I've tried using "-v" as mentioned like this:
$ CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=7 go build \
-x -ldflags "-extldflags -v" .
It gives me more than 100 lines of messages, so I don't post it here unless it's necessary. The go build command seems to try compiling the source with the clang bundled with Xcode.
3A. The Build Command (Successful, but...)
Given the hint that the wrong compiler is found, I tried to set $CC like this:
$ CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=7 \
CC=/path/to/arm-linux-androideabi/bin/clang go build .
arm-linux-androideabi is the output from make_standalone_toolchain.py (or make-standalone-toolchain.sh).
3B. The Output
The executable (named cross) is successfully built, with the following messages:
# github.com/asukakenji/cross
warning: unable to find runtime/cgo.a
I tried adb push it and run it with adb shell on Android, it worked fine.
My Questions
Why does it need a C compiler? Doesn't Go cross-compile out-of-the-box?
When building for Linux (instead of Android), the compilation works fine:
$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build .
Why?
The go build command keeps looking for runtime/cgo.a, even when I didn't use CGO in the source code, and even when I set CGO_ENABLED=0. How can I get rid of the warning? How is it harmful not having one?
if you run that code you find the android as an official target platform
listed as GOOS/GOARCH
$go tool dist list
Android isn't official target platform for cross-compilation. If all you need are command-line executables then you can set GOOS=linux because android is a linux under the hood, else take a look at https://github.com/golang/go/wiki/Mobile
The cgo requirement might be because go requires libc for DNS lookups on Android: https://github.com/golang/go/issues/8877
You need to use Android NDK to compile for android, you can download it from the link, or from Android Studio:
Then you can find the compilerlink in the route as below:
Last login: Fri Sep 4 09:25:16 on console
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Hasans-Air:~ hajsf$ pwd
/Users/hajsf
Hasans-Air:~ hajsf$ cd Library
Hasans-Air:Library hajsf$ cd android
Hasans-Air:android hajsf$ cd sdk
Hasans-Air:sdk hajsf$ cd ndk
Hasans-Air:ndk hajsf$ ls
21.3.6528147
Hasans-Air:ndk hajsf$ cd 21.3.6528147
Hasans-Air:21.3.6528147 hajsf$ cd toolchains
Hasans-Air:toolchains hajsf$ cd llvm
Hasans-Air:llvm hajsf$ cd prebuilt
Hasans-Air:prebuilt hajsf$ ls
darwin-x86_64
Hasans-Air:prebuilt hajsf$ cd darwin-x86_64
Hasans-Air:darwin-x86_64 hajsf$ cd bin
Hasans-Air:bin hajsf$ pwd
/Users/hajsf/Library/android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin
Then you can use the one reflectiong:
Archeticture you want to build your android app for, like aarch64
Android API you want to compile for, like Android 30
You can see full list of availbe options there, and you can seect the one you want like aarch64-linux-android30-clang
If you are at Windows 10 you'll find it at:
"C:\Users\${user}\AppData\Local\Android\Sdk\ndk\${NKD_version}\toolchains\llvm\prebuilt\windows-x86_64\bin\aarch64-linux-android30-clang"
There are 4 avaiailble linkers which are:
//CC_FOR_TARGET=/Users/hajsf/Library/android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android30-clang
//CC_FOR_TARGET=/Users/hajsf/Library/android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android30-clang
//CC_FOR_TARGET=/Users/hajsf/Library/android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/x86_64-linux-android30-clang
//CC_FOR_TARGET=/Users/hajsf/Library/android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi30-clang
After that only you can do cross copiling, as:
$ CGO_ENABLED=1
$ GOOS=android
$ GOARCH=arm64
$ CC_FOR_TARGET=/Users/hajsf/Library/android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android30-clang
$ go build -buildmode=c-shared -o lib-aarch64-android30.so lib.go
And a simple cgo file lib.go could be:
package main
import "C"
import "fmt"
//export HelloWorld
func HelloWorld() {
fmt.Printf("hello world from GO\n")
}
//export GetKey
func GetKey() *C.char {
theKey := "123-456-789"
return C.CString(theKey)
}
func main() {}
As shown copilation completed successfuly, and both lib-aarch64-android30.so and ib-aarch64-android30.h had been generated without any error.
Quick note, not to go far from the scope of the question, if you return a string, then the return value from this function must be explicitly freed in the C code if if you call it from C code, but as you call it from garbage collector environment, Java/Kotlin you do not want to worry about it.
If freeing the allocated buffer isn't convenient, its common to fill a buffer provided by the caller:
func GetKey(buff *C.char, n int) int
If you can allocate the memory but don't want to handle C strings, you can insert the buffer into a pointer and return the size.
func GetKey(buff **C.char) int
I'm trying to build an apk file from command line. I created a sample project usng the following command:
android create project --target 1 --name MyApp --path ./MyProject --activity MyActivity --package com.example.myapp
Which created the following structure:
/bin
/res
/src
/libs
AndroidManifest.xml
ant.properties
build.xml
local.properties
proguard-project.txt
project.properties
Now when I try to build the project, I get:
$ gradle build
gradle will not execute and completion _gradle exists.
I couldn't find any info on this error, so I ran:
$ _gradle build
_arguments:comparguments:312: can only be called from completion function
user has logged on pts/7 from :0.0.
Any hints on what am I doing wrong? Thanks!
android create project creates project in structure expected by Eclipse, not gradle based (Android Studio) projects.
I was able to build the apk using the following lines:
ant debug
adb install bin/HelloWorld-debug.apk
I have downloaded Cocos2d-x-3.1.1 but it does not include #create-android-project.bat and #create-android-project.sh then i download these 2 files from the internet and i tried to create project i receive the error. anyone have any idea please kindly help.
.............
Resolved location library project to C:\ADT\cocos2d-x\cocos2dx\platform\android\java
Error: Project folder 'C:\ADT\cocos2d-x\cocos2dx\platform\android\java' is not valid directory
Error: No Android manifest at: C:\ADT\cocos2d-x\cocos2dx\platform\android\java
Error!!!
Don't run in cygwin. You should run corresponding bat.
Press any key to continue.
$ cocos new ProjName -p com.compnyName.ProjName -l cpp
You should use cocos2d-console for creating project.
$ cocos2d-x-3.1.1/tools/cocos2d-console/bin/cocos new -d . -p com.example.testproject -l cpp TestProject
i am trying to install Phonegap on Ubuntu 13.04, i have installed the Android SDK with all available Packages, but running the following command:
cordova platform add android
fails with an unexpected error:
[Error: An error occured during creation of android sub-project. An unexpected error occurred: "$ANDROID_BIN" create project --target $TARGET --path "$PROJECT_PATH" --package $PACKAGE --activity $ACTIVITY &>/dev/null exited with 1
Deleting project...
I have set the PATH Variables for Android (tools / platform-tools) and java and ant are installed.
Why does this happen? How can i get a more detailed error message?
have you tried running command with sudo?
it could be a permissions issue.
If still not working, try running it using verbose mode i.e. sudo -d cordova...
In case this is due to activity name whitespaces, see comments for this answer.
There is an issue reported in https://issues.apache.org/jira/browse/CB-4198, for which I've sent a pull request to remove whitespaces https://github.com/phonegap/phonegap/pull/39.
As #José said, the "hello" example doesn't work because spaces are not allowed.
Changing it to "HelloWorld" solves the problem.
remove the space in between name tags in config.xml
MyAppName< name>
In my case, using debian wheezy, the example from: http://docs.phonegap.com/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface does not work with this error:
[Error: An error occured during creation of android sub-project. An unexpected error occurred: "$ANDROID_BIN" create project --target $TARGET --path "$PROJECT_PATH" --package $PACKAGE --activity $ACTIVITY &>/dev/null exited with 1
Deleting project...
]
After adding $JAVA_HOME (Java sun, with openjdk did't work) and $PATH the andriod sdk path to .../sdk/platform-tools:../sdk/tool
The solution in my case was the project name:
The example that doesn't work:
cordova create HelloWorld com.example.hello "Hello World"
THIS works:
cordova create HelloWorld com.example.hello HelloWorld
Make sure your package and project names are correct, following the com.mycompanyname.myappname format without any numbers or dashes.
Here's the issue being tracked by PhoneGap.
If you open up the create file (phonegap-2.7.0/lib/android/bin/create) with textEdit, there is a line that lists
ANDROID_BIN=”${ANDROID_BIN:=$( which android )}”.
The “which android” is the cause of the issue
If you replace this line with the full path to your android tools (SDK), it should resolve the issue. It looked like this:
ANDROID_BIN=/Users/cswjs/Documents/Dev/adt-bundle/sdk/tools/android
OR try modify ~/.bash_profile using open ~/.bash_profile to full PATH
export PATH=${PATH}:/Users/cswjs/Documents/Dev/adt-bundle/sdk/platform-tools:/Users/cswjs/Documents/Dev/adt-bundle/sdk/tools
And use cordova create foo com.example.foo foo to create new project named foo. Make sure project name should be same.
Hope this could help someone!
IN my case there are many places in create script where u need to remove >null to see real logs. and i finally resolved my issues by
sudo chown -R sachinsharma ~/.cordova