《QT on Android核心编程》
if your user name :niuyi
mkdir /home/niuyi/qtforandroid
cd /home/niuyi/qtforandroid
1、安装jdk8(选这个)
添加ppa源
sudo add-apt-repository ppa:openjdk-r/ppa
更新并等待自动安装
sudo apt-get update
sudo apt-get install openjdk-8-jdk
以上便安装成功,如果系统中存在多个jdk版本,用以下命令切换并选择合适版本即可
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo gedit /etc/profile.d/jdk8.sh
添加下面内容:
{
echo "set java environment"
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 # 注意和安装路径一致
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
}
测试Java运行环境
java -version
javac -version
2、linux 64 安装ant
参考
https://my.oschina.net/mynote/blog/92048
linux 64 bit ANT
安装:
tar jxvf apache-ant-1.9.7-bin.tar.bz2
sudo gedit /etc/profile.d/ant.sh
添加下面内容:
{
#set ant environment
echo "set ant environment"
export ANT_HOME=/home/niuyi/qtforandroid/apache-ant-1.9.7
export PATH=$PATH:$ANT_HOME/bin
}
测试
ant -v
3、安装NDK
linux 64bit ndk 32bit:(选这个)
linux 64 bit NDK 下载
安装方法:
请确保你已安装了Android SDK
chmod a+x android-ndk-r10d-linux-x86_64.bin
./android-ndk-r10d-linux-x86_64.bin
sudo gedit /etc/profile.d/ndk.sh
{
#set ndk environment
echo "set ndk environment"
# NDK=/home/niuyi/qtforandroid/android-ndk-r10 # ndk 64bit 注意和安装路径一致
NDK=/home/niuyi/qtforandroid/android-ndk-r10d # ndk 32bit 注意和安装路径一致
export PATH=$NDK:$PATH
}
4、安装Android SDK
参考
http://www.cnblogs.com/sink_cup/archive/2011/10/31/ubuntu_x64_android_sdk_java.html
linux 64 bit The android sdk tools
tar -zxvf android-sdk_r24.4.1-linux.tgz
sudo gedit /etc/profile.d/android_sdk.sh
添加下面内容:
{
#set sdk for android environment
echo "set sdk for android environment"
export ANDROID_HOME=/home/niuyi/qtforandroid/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export JAVA_CMD=/usr/lib/jvm/java-7-openjdk-amd64/bin/java
}
source /etc/profile
启动Android SDK Manager:
android
根据需要,选择最新版的Android SDK Platform-tools、Samples for SDK等等下载即可(约2.6GB)。
注意:一定要安装Android Support Repository,否则gradle会报错。
如果下载速度慢,有2个办法:
a、配hosts:ping g.cn,为dl-ssl.google.com设置hosts,并且在Android SDK Manager——》菜单——》Tools——》Options中选中“Force https to http”
b、国内cdn镜像下载:todo
5、设置adb
cd home/niuyi/qtforandroid/android-sdk-linux/platform-tools
./adb devices
问题:如果缺少库libstdc++.so.6或启动不了则:
sudo apt-get install libstdc++6:i386 lib32stdc++6 lib32z1 lib32ncurses5
6、Ubuntu 14.04上安装Android Studio
sudo apt-add-repository ppa:paolorotolo/android-studio
sudo apt-get update
sudo apt-get install android-studio
如果要把Android Studio添加到启动栏,你需要如下操作
打开Android Studio,点击Configure选择Create Desktop Entry,这样Android Studio应该在dash中创建快捷方式了
7、qt creator安装
ubuntu 14.04 64bit 下qt5.6 for android下载地址:
chmod a+x qt-opensource-linux-x64-android-5.6.0.run
./qt-opensource-linux-x64-android-5.6.0.run
参考:
http://blog.csdn.net/u013600225/article/details/52078220
问题1 使用QT编译Android项目时总是提示头文件编译错误,类似下面
G:\androidsdk\android-ndk-r10d\sources\cxx-stl\gnu-libstdc++\4.9\include\cstdlib:72: error: stdlib.h: No such file or directory
#include
G:\androidsdk\android-ndk64-r10-windows-x86_64\android-ndk-r10\sources\cxx-stl\gnu-libstdc++\4.9\include/cwchar:44:19: fatal error: wchar.h: No such file or directory
#include
compilation terminated.
makefile:1080: recipe for target 'xxx.obj' failed
解决方案: ^
来自一个国外网友的解决方案:
以下是解决答案:
Solved.
解决方案:It appeared I had a 64-bit NDK installed even though I thought I had downloaded a 32-bit NDK.
I blew away all NDK remnants and downloaded new 32-bit r10 NDK and now my Android x86 emulator is launching my Qt hello world app.
android-ndk32-r10-darwin-x86.tar.bz2
意思是要统一使用32位的NDK,QT Creator.
解决方案:我的解决方案也是这样,我的机器是64位,我NDK安装了64位,但是QTCreator是32位,这样就会有问题,把NDK重新下载一个32位的就OK了
问题2 编译应用程序出现:
Error:Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
解决:
更换JDK版本为1.8
以下为参考资源
************************************************************************************************************************************************
if your user name :niuyi
mkdir /home/niuyi/qtforandroid
cd /home/niuyi/qtforandroid
1、安装java1.7 for android 5.1
chmod +x jdk-7u79-linux-x64.tar.gz
tar xvf jdk-7u79-linux-x64.tar.gz
sudo gedit /etc/profile.d/jdk7.sh
添加下面内容:
{
echo "set java 7 environment"
JAVA_HOME=/home/niuyi/qtforandroid/jdk1.7.0_79 # 注意和安装路径一致
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
}
source /etc/profile
测试
java -version
2、安装Android SDK
参考
http://www.cnblogs.com/sink_cup/archive/2011/10/31/ubuntu_x64_android_sdk_java.html
安装jdk7
sudo apt-get install openjdk-7-jdk
安装jdk8(选这个)
添加ppa源
sudo add-apt-repository ppa:openjdk-r/ppa
更新并等待自动安装
sudo apt-get update
sudo apt-get install openjdk-8-jdk
以上便安装成功,如果系统中存在多个jdk版本,用以下命令切换并选择合适版本即可
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo gedit /etc/profile.d/jdk7.sh
添加下面内容:
{
echo "set java environment"
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 # 注意和安装路径一致
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
}
测试Java运行环境
java -version
javac -version
linux 64 bit The android sdk tools
tar -zxvf android-sdk_r24.4.1-linux.tgz
sudo gedit /etc/profile.d/android_sdk.sh
添加下面内容:
{
#set sdk for android environment
echo "set sdk for android environment"
export ANDROID_HOME=/home/niuyi/qtforandroid/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export JAVA_CMD=/usr/lib/jvm/java-7-openjdk-amd64/bin/java
}
source /etc/profile
启动Android SDK Manager:
android
根据需要,选择最新版的Android SDK Platform-tools、Samples for SDK等等下载即可(约2.6GB)。
注意:一定要安装Android Support Repository,否则gradle会报错。
如果下载速度慢,有2个办法:
a、配hosts:ping g.cn,为dl-ssl.google.com设置hosts,并且在Android SDK Manager——》菜单——》Tools——》Options中选中“Force https to http”
b、国内cdn镜像下载:todo
3、linux 64 安装ant
参考
https://my.oschina.net/mynote/blog/92048
linux 64 bit ANT
安装:
tar jxvf apache-ant-1.9.7-bin.tar.bz2
sudo gedit /etc/profile.d/ant.sh
添加下面内容:
{
#set ant environment
echo "set ant environment"
export ANT_HOME=/home/niuyi/qtforandroid/apache-ant-1.9.7
export PATH=$PATH:$ANT_HOME/bin
}
测试
ant -v
4、linux 64 bit NDK
linux 64bit , ndk 64bit:
android-ndk64-r10-linux-x86_64.tar.bz2
安装方法:
请确保你已安装了Android SDK
tar jxvf android-ndk64-r10-linux-x86_64.tar.bz2
sudo gedit /etc/profile.d/ndk.sh
{
#set ndk environment
echo "set ndk environment"
NDK=/home/niuyi/qtforandroid/android-ndk-r10 # ndk 64bit 注意和安装路径一致
# NDK=/home/niuyi/qtforandroid/android-ndk-r10d # ndk 32bit 注意和安装路径一致
export PATH=$NDK:$PATH
}
source /etc/profile
测试
ndk-build
输出
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/home/niuyi/qtforandroid/android-ndk-r10/build/core/build-local.mk:148: *** Android NDK: Aborting . Stop.
参考:
http://blog.csdn.net/davebobo/article/details/52446986
linux 64bit ndk 32bit:(选这个)
linux 64 bit NDK 下载
安装方法:
请确保你已安装了Android SDK
chmod a+x android-ndk-r10d-linux-x86_64.bin
./android-ndk-r10d-linux-x86_64.bin
sudo gedit /etc/profile.d/ndk.sh
{
#set ndk environment
echo "set ndk environment"
# NDK=/home/niuyi/qtforandroid/android-ndk-r10 # ndk 64bit 注意和安装路径一致
NDK=/home/niuyi/qtforandroid/android-ndk-r10d # ndk 32bit 注意和安装路径一致
export PATH=$NDK:$PATH
}
假设解压出来的目录在path/to/ndk下
在android studio工程的local.properties文件中加入 ndk.dir=path/to/ndk
或者设置ANDROID_NDK_HOME环境变量为path/to/ndk 比如在~/.bashrc中加上 export ANDROID_NDK_HOME=/opt/android-ndk-r10d然后重启
------------------------------------------------------------------------------------------------------------
5、qt creator安装
ubuntu 14.04 64bit 下qt5.6 for android下载地址:
chmod a+x qt-opensource-linux-x64-android-5.6.0.run
./qt-opensource-linux-x64-android-5.6.0.run
参考:
http://blog.csdn.net/u013600225/article/details/52078220
6、设置adb
cd home/niuyi/qtforandroid/android-sdk-linux/platform-tools
./adb devices
问题:如果缺少库libstdc++.so.6或启动不了则:
sudo apt-get install libstdc++6:i386 lib32stdc++6 lib32z1 lib32ncurses5
6、Ubuntu 14.04上安装Android Studio
sudo apt-add-repository ppa:paolorotolo/android-studio
sudo apt-get update
sudo apt-get install android-studio
如果要把Android Studio添加到启动栏,你需要如下操作
打开Android Studio,点击Configure选择Create Desktop Entry,这样Android Studio应该在dash中创建快捷方式了
问题1 使用QT编译Android项目时总是提示头文件编译错误,类似下面
G:\androidsdk\android-ndk-r10d\sources\cxx-stl\gnu-libstdc++\4.9\include\cstdlib:72: error: stdlib.h: No such file or directory
#include
G:\androidsdk\android-ndk64-r10-windows-x86_64\android-ndk-r10\sources\cxx-stl\gnu-libstdc++\4.9\include/cwchar:44:19: fatal error: wchar.h: No such file or directory
#include
compilation terminated.
makefile:1080: recipe for target 'xxx.obj' failed
解决方案: ^
来自一个国外网友的解决方案:
以下是解决答案:
Solved.
解决方案:It appeared I had a 64-bit NDK installed even though I thought I had downloaded a 32-bit NDK.
I blew away all NDK remnants and downloaded new 32-bit r10 NDK and now my Android x86 emulator is launching my Qt hello world app.
android-ndk32-r10-darwin-x86.tar.bz2
意思是要统一使用32位的NDK,QT Creator.
解决方案:我的解决方案也是这样,我的机器是64位,我NDK安装了64位,但是QTCreator是32位,这样就会有问题,把NDK重新下载一个32位的就OK了
阅读(1913) | 评论(0) | 转发(0) |