在Debian/Ubuntu上安装 Eclipse, 不管是apt-get 还是直接下载的, 当Help -> Install New Software 时,都会报相同的错误,Unable to connect to repository
使用android-sdk 的 $ android update sdk 时, 也有类似错误.
但是在Windows安装却没有问题,而且Linux下 curl 查看,可以连接到服务器的。
后来网上看到,应该是所有的Java app都会出现 “Unable to connect to”。
解决方法:
将/etc/sysctl.d/bindv6only.conf 中的 net.ipv6.bindv6only = 1 改为 net.ipv6.bindv6only = 0
$ sudo invoke-rc.d procps restart
Oct 25, 2010
Oct 23, 2010
Setup Android Develop Environment
0. install Eclipse
Download Eclipse from http://www.eclipse.org/downloads/, Eclipse IDE for Java Developers.
tar xvf eclipse-java-galileo-linux-gtk.tar.gz
1. Install ADT
Error message: org.eclipse.wst.sse.core 0.0.0' but it could not be found
# install ADT for developing Android
Start Eclipse, Help -> Install New Software,
Add site:
Google Android Tools - https://dl-ssl.google.com/android/eclipse/
Eclipse GEF - http://download.eclipse.org/tools/gef/updates/releases/
Eclipse EMF - http://download.eclipse.org/modeling/emf/updates/releases/
Eclipse GMF - http://download.eclipse.org/modeling/gmf/updates/releases
Eclipse Webtools - http://download.eclipse.org/webtools/updates/
Google eclipse Plugin - http://dl.google.com/eclipse/plugin/3.5
Choose "Google Android Tools", then select "Developer Tools" and install it.
2. Install Android SDK
download android-sdk_r07-linux_x86.tgz
$ tar xvf android-sdk_r07-linux_x86.tgz
$ cd android-sdk-linux_x86
$ tools/android update sdk
modify ~/.bashrc, add android-sdk-linux_x86/tools to PATH environ variable.
3. Create Android target
$ tools/android create avd --target "android-8" --name "android-8"
$ tools/android create avd --target "android-7" --name "android-7"
4. Setup Eclipse
Eclipse, Window -> Preferences -> Android, SDK Location, locate to your android sdk directory.
Download Eclipse from http://www.eclipse.org/downloads/, Eclipse IDE for Java Developers.
tar xvf eclipse-java-galileo-linux-gtk.tar.gz
1. Install ADT
Error message: org.eclipse.wst.sse.core 0.0.0' but it could not be found
# install ADT for developing Android
Start Eclipse, Help -> Install New Software,
Add site:
Google Android Tools - https://dl-ssl.google.com/android/eclipse/
Eclipse GEF - http://download.eclipse.org/tools/gef/updates/releases/
Eclipse EMF - http://download.eclipse.org/modeling/emf/updates/releases/
Eclipse GMF - http://download.eclipse.org/modeling/gmf/updates/releases
Eclipse Webtools - http://download.eclipse.org/webtools/updates/
Google eclipse Plugin - http://dl.google.com/eclipse/plugin/3.5
Choose "Google Android Tools", then select "Developer Tools" and install it.
2. Install Android SDK
download android-sdk_r07-linux_x86.tgz
$ tar xvf android-sdk_r07-linux_x86.tgz
$ cd android-sdk-linux_x86
$ tools/android update sdk
modify ~/.bashrc, add android-sdk-linux_x86/tools to PATH environ variable.
3. Create Android target
$ tools/android create avd --target "android-8" --name "android-8"
$ tools/android create avd --target "android-7" --name "android-7"
4. Setup Eclipse
Eclipse, Window -> Preferences -> Android, SDK Location, locate to your android sdk directory.
Android通过JNI调用native code
0. 用Eclipse 创建 Android Project
1. 创建Java类,这个类的作用是描述native code中的函数, 比如DemoLib
2. 生成native code头文件, javah -jni ...
3. 实现native code
4. 编写jni/Android.mk
5. 编译native code, 生成动态库
6. 在Java程序中调用native code
7. 测试
0. 先通过 Eclipse 创建一个Android Project
Project name: LibDemoTest
Build Target: Android 2.2
Package name: org.ox0spy.libdemotest
Create Activity: LibDemoTest
1. 在src中添加一个新类 - DemoLib
Package: org.ox0spy.libdemotest
Name: DemoLib
DemoLib.java 内容如下:
package org.ox0spy.libdemotest;
public class DemoLib {
static {
System.loadLibrary("demo");
}
public native int multiply(int a, int b);
public native String greet();
}
注意: 编辑完了一定保存下.
2. 生成native code的头文件
$ cd ~/workspace/LibDemoTest/bin
$ javah -jni org.ox0spy.libdemotest.DemoLib
$ mkdir ../jni
$ mv org_ox0spy_libdemotest_DemoLib.h ../jni/
3. 实现native code, demo.c 内容如下:
#include "org_ox0spy_libdemotest_DemoLib.h"
JNIEXPORT jint JNICALL Java_org_ox0spy_libdemotest_DemoLib_multiply
(JNIEnv * env, jobject obj, jint a, jint b)
{
return a*b;
}
JNIEXPORT jstring JNICALL Java_org_ox0spy_libdemotest_DemoLib_greet
(JNIEnv * env, jobject obj)
{
return (*env)->NewStringUTF(env, "Hello Android!");
}
4. 编写jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := demo.c
LOCAL_MODULE := demo
include $(BUILD_SHARED_LIBRARY)
5. 编译native code
$ cd ~/workspace/LibDemoTest
$ ndk-build # 先将android-ndk-r4b加入你的PATH中
6. Java程序中调用native code, 我在LibDemoTest.java中用到了native code
LibDemoTest内容如下:
package org.ox0spy.libdemotest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class LibDemoTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DemoLib demoLib = new DemoLib();
int result = demoLib.multiply(100, 100);
String str = demoLib.greet();
TextView tv = new TextView(this);
tv.setText(str + "\n" + Integer.toString(result));
setContentView(tv);
}
}
7. 测试, Eclipse, Run -> Run
我碰到的错误:
No implementation found for native
碰到这个错误时,我是用System.load("demo")加载动态库的,而且从logcat的输出发现libdemo.so已经成功加载了。
我是因为一开始没有用javah -jni 生成头文件,自己写的native code函数声明是:
jint multiply(jint a, jint b);
所以, 只要用javah -jni 生成头文件应该就不会碰到这个问题了.
1. 创建Java类,这个类的作用是描述native code中的函数, 比如DemoLib
2. 生成native code头文件, javah -jni ...
3. 实现native code
4. 编写jni/Android.mk
5. 编译native code, 生成动态库
6. 在Java程序中调用native code
7. 测试
0. 先通过 Eclipse 创建一个Android Project
Project name: LibDemoTest
Build Target: Android 2.2
Package name: org.ox0spy.libdemotest
Create Activity: LibDemoTest
1. 在src中添加一个新类 - DemoLib
Package: org.ox0spy.libdemotest
Name: DemoLib
DemoLib.java 内容如下:
package org.ox0spy.libdemotest;
public class DemoLib {
static {
System.loadLibrary("demo");
}
public native int multiply(int a, int b);
public native String greet();
}
注意: 编辑完了一定保存下.
2. 生成native code的头文件
$ cd ~/workspace/LibDemoTest/bin
$ javah -jni org.ox0spy.libdemotest.DemoLib
$ mkdir ../jni
$ mv org_ox0spy_libdemotest_DemoLib.h ../jni/
3. 实现native code, demo.c 内容如下:
#include "org_ox0spy_libdemotest_DemoLib.h"
JNIEXPORT jint JNICALL Java_org_ox0spy_libdemotest_DemoLib_multiply
(JNIEnv * env, jobject obj, jint a, jint b)
{
return a*b;
}
JNIEXPORT jstring JNICALL Java_org_ox0spy_libdemotest_DemoLib_greet
(JNIEnv * env, jobject obj)
{
return (*env)->NewStringUTF(env, "Hello Android!");
}
4. 编写jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := demo.c
LOCAL_MODULE := demo
include $(BUILD_SHARED_LIBRARY)
5. 编译native code
$ cd ~/workspace/LibDemoTest
$ ndk-build # 先将android-ndk-r4b加入你的PATH中
6. Java程序中调用native code, 我在LibDemoTest.java中用到了native code
LibDemoTest内容如下:
package org.ox0spy.libdemotest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class LibDemoTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DemoLib demoLib = new DemoLib();
int result = demoLib.multiply(100, 100);
String str = demoLib.greet();
TextView tv = new TextView(this);
tv.setText(str + "\n" + Integer.toString(result));
setContentView(tv);
}
}
7. 测试, Eclipse, Run -> Run
我碰到的错误:
No implementation found for native
碰到这个错误时,我是用System.load("demo")加载动态库的,而且从logcat的输出发现libdemo.so已经成功加载了。
我是因为一开始没有用javah -jni 生成头文件,自己写的native code函数声明是:
jint multiply(jint a, jint b);
所以, 只要用javah -jni 生成头文件应该就不会碰到这个问题了.
Oct 16, 2010
Ubuntu 升级到 10.10, 解决Firefox无法播放flash
昨天看了Tsung的Ubuntu 10.04 升級到10.10 Maverick Meerkat 與 問題排除 晚上回去就把我的ubuntu 10.04 desktop升级了,升级很简单, 一路也很顺利。
想想,这是我用Linux这么多年来,第一次升级系统, 每次我都觉得升级太麻烦, 要等好长时间,所以,直接下载iso,重新安装;昨天睡觉前开始升级,早上起来就好了,整体感觉很好。
10.04 desktop 升级到 10.10
Alt + F2, 输入 update-manager -d , 下面根据提示操作就对了。
目前唯一的问题是 Firefox 看不了 flash, 从 Firefox -> Tools -> Add-ons 看到播放flash用的是 gnash 而不是 adobe-flash,虽然 dpkg -l | grep adobe-flash , 可以看到 adobe-flashplugin已经安装了,但 firefox add-ons 上看不到, 我认为是这两个冲突导致的。
卸载 gnash
$ sudo apt-get purge gnash
$ sudo apt-get purge gnash-common
重新安装 adobe-flash,问题解决.
$ sudo apt-get install --reinstall adobe-flashplugin
想想,这是我用Linux这么多年来,第一次升级系统, 每次我都觉得升级太麻烦, 要等好长时间,所以,直接下载iso,重新安装;昨天睡觉前开始升级,早上起来就好了,整体感觉很好。
10.04 desktop 升级到 10.10
Alt + F2, 输入 update-manager -d , 下面根据提示操作就对了。
目前唯一的问题是 Firefox 看不了 flash, 从 Firefox -> Tools -> Add-ons 看到播放flash用的是 gnash 而不是 adobe-flash,虽然 dpkg -l | grep adobe-flash , 可以看到 adobe-flashplugin已经安装了,但 firefox add-ons 上看不到, 我认为是这两个冲突导致的。
卸载 gnash
$ sudo apt-get purge gnash
$ sudo apt-get purge gnash-common
重新安装 adobe-flash,问题解决.
$ sudo apt-get install --reinstall adobe-flashplugin
Oct 14, 2010
public access git on ubuntu/debian
前面介绍了
gitosis搭建: setting up gitosis on ubuntudebian
gitweb搭建: setting up gitweb on ubuntudebian
gitosis权限: gitosis权限
现在,有个项目,自己项目组的人肯定要有commit权限,但其他人也要有readonly权限,虽然,可以在gitosis-admin 中添加readonly组,但,我们不可能找每个人要ssh public key吧
这时候, 可以用 git-daemon
$ sudo apt-get install git-daemon-run
修改 /etc/sv/git-daemon/run , 把git repo的路径设置正确就行
$ cat /etc/sv/git-daemon/run
#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec chpst -ugitdaemon \
/usr/lib/git-core/git-daemon --verbose --base-path=/srv/gitosis/repositories
把要让匿名访问的git repository目录下放一个名为 git-daemon-export-ok 的空文件.
$ sudo sv restart git-daemon
$ git clone git://mypc/Your-test.git
gitosis搭建: setting up gitosis on ubuntudebian
gitweb搭建: setting up gitweb on ubuntudebian
gitosis权限: gitosis权限
现在,有个项目,自己项目组的人肯定要有commit权限,但其他人也要有readonly权限,虽然,可以在gitosis-admin 中添加readonly组,但,我们不可能找每个人要ssh public key吧
这时候, 可以用 git-daemon
$ sudo apt-get install git-daemon-run
修改 /etc/sv/git-daemon/run , 把git repo的路径设置正确就行
$ cat /etc/sv/git-daemon/run
#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec chpst -ugitdaemon \
/usr/lib/git-core/git-daemon --verbose --base-path=/srv/gitosis/repositories
把要让匿名访问的git repository目录下放一个名为 git-daemon-export-ok 的空文件.
$ sudo sv restart git-daemon
$ git clone git://mypc/Your-test.git
Oct 10, 2010
gitosis权限设置
通过gitosis搭建git服务器可以参考 http://ox0spy.blogspot.com/2010/10/setting-up-gitosis-on-ubuntudebian.html.
下面看下gitosis权限设置
gitosis有组(group)和成员(members), 权限就是对repository的访问限制.
有两个关键字修饰 repository ,一个是 writable, 一个是 readonly.
writable 意思是,对这个repository 有写权限
readonly 是, 对这个repository 只有读权限
最常见的例子:
[group gitosis-admin]
writable = gitosis-admin # 注意,后面不要加 .git
members = ox0spy@lucid
这三句话是啥意思呢?
第1句,定义一个组, 名字为 gitosis-admin
第2句, writable = 后面跟的是仓库名, 只是这个仓库名是去掉.git的,所以, 我们在 git clone 时,要自己加上 .git,如下:
$ git clone gitosis@localhost:gitosis-admin.git # 注意最后的 .git
writable 后面可以跟很多个仓库名, 他们以whitespace分开, 一般以空格分隔,如下:
writable = gitosis-admin android mytest
第3句, members 说明这个组的成员, 成员名是 username@hostname , @hostname 不能去,否则会报错.
成员之间也通过 whitespace 分隔,通常用空格分隔.
可以发现,成员属于某个组, 而对repository的访问权限是通过组控制的.
这样的话,如果同一个repository,想让某些用户只能读,不能写,就必须新建一个组, 下面就看下怎么实现这个功能.
[group test] # 该组用户可写
members = ox0spy@lucid lfs@debian
writable = mytest
[group test_ro] # 该组用户只读
members = toor@ubuntu
readonly = mytest # 只读,这里是readonly 而不是 readable
这样,toor@ubuntu 就只能对 gitosis@Your-server:mytest.git 进行读
members 可以包含其他组的所有成员
[group member_test]
writable = memberTest
readonly = mytest
members = ox0spy@lucid @test
# 这里的 @test 就是上面 test组的所有成员 (ox0spy@lucid lfs@debian)
最后,要说的是, 一个组可以只有 members, 没有 writable 和 readonly,如下:
[group another_group]
members = monkey@abc cow@gentoo
这个组只是为了被其他组包含而定义.
下面看下gitosis权限设置
gitosis有组(group)和成员(members), 权限就是对repository的访问限制.
有两个关键字修饰 repository ,一个是 writable, 一个是 readonly.
writable 意思是,对这个repository 有写权限
readonly 是, 对这个repository 只有读权限
最常见的例子:
[group gitosis-admin]
writable = gitosis-admin # 注意,后面不要加 .git
members = ox0spy@lucid
这三句话是啥意思呢?
第1句,定义一个组, 名字为 gitosis-admin
第2句, writable = 后面跟的是仓库名, 只是这个仓库名是去掉.git的,所以, 我们在 git clone 时,要自己加上 .git,如下:
$ git clone gitosis@localhost:gitosis-admin.git # 注意最后的 .git
writable 后面可以跟很多个仓库名, 他们以whitespace分开, 一般以空格分隔,如下:
writable = gitosis-admin android mytest
第3句, members 说明这个组的成员, 成员名是 username@hostname , @hostname 不能去,否则会报错.
成员之间也通过 whitespace 分隔,通常用空格分隔.
可以发现,成员属于某个组, 而对repository的访问权限是通过组控制的.
这样的话,如果同一个repository,想让某些用户只能读,不能写,就必须新建一个组, 下面就看下怎么实现这个功能.
[group test] # 该组用户可写
members = ox0spy@lucid lfs@debian
writable = mytest
[group test_ro] # 该组用户只读
members = toor@ubuntu
readonly = mytest # 只读,这里是readonly 而不是 readable
这样,toor@ubuntu 就只能对 gitosis@Your-server:mytest.git 进行读
members 可以包含其他组的所有成员
[group member_test]
writable = memberTest
readonly = mytest
members = ox0spy@lucid @test
# 这里的 @test 就是上面 test组的所有成员 (ox0spy@lucid lfs@debian)
最后,要说的是, 一个组可以只有 members, 没有 writable 和 readonly,如下:
[group another_group]
members = monkey@abc cow@gentoo
这个组只是为了被其他组包含而定义.
setting up gitweb on ubuntu/debian
1. 安装
$ sudo apt-get install gitweb
2. 设置
修改 /etc/gitweb.conf
# projectroot 设置成你自己的仓库路径, 这是gitosis默认路径
$projectroot = "/srv/gitosis/repositories/";
view /etc/apache2/conf.d/gitweb # 一般不用修改
$ cp -r /usr/share/gitweb /var/www
3. 测试
$ curl localhost/gitweb/
$ sudo apt-get install gitweb
2. 设置
修改 /etc/gitweb.conf
# projectroot 设置成你自己的仓库路径, 这是gitosis默认路径
$projectroot = "/srv/gitosis/repositories/";
view /etc/apache2/conf.d/gitweb # 一般不用修改
$ cp -r /usr/share/gitweb /var/www
3. 测试
$ curl localhost/gitweb/
Oct 8, 2010
setting up gitosis on ubuntu/debian
1. install
# run on server
$ sudo apt-get install git-core gitosis
2. generate ssh key
# run on your pc
$ ssh-keygen -t rsa
3. upload the ssh public key
# run on your pc
$ scp ~/.ssh/id_rsa.pub USER@YOUR_SERVER:/tmp
4. create admin repository
# run on server
$ sudo -H -u gitosis gitosis-init < /tmp/id_rsa.pub # monkey's ssh public key
$ sudo chmod 755 /srv/gitosis/repositories/gitosis-admin.git/hooks/post-update
5. checkout gitosis-admin
# run on your pc
$ git clone gitosis@YOUR_SERvER:gitosis-admin.git
6. grante right for members
# run on your pc, add new group - android
[group android] # team name
writable = 0xdroid-0x5 0xdroid-0x4 # project name
members = monkey@debian cow@ubuntu # members
# add cow's ssh public key
$ git add keydir/cow@ubuntu.pub gitosis.conf
# grante cow commit right to android
$ git commit -m "Granted cow commit right to android"
$ git push # now, cow has the commit right.
7. create new repositories
There are two ways to commit your code:
a. checkin your codes from zero
# create new repositories - 0xdroid-0x5.git
$ cd YOUR-CODE-DIR
$ mkdir 0xdroid-0x5.git && cd 0xdroid-0x5.git
$ git init
# modify .gitignore
$ git remote add origin gitosis@YOUR_SERVER:0xdroid-0x5.git
$ git add .
$ git commit -m "initial import"
$ git push origin master:refs/heads/master
b. checkin your codes from old git repo
$ cd YOUR-OlD-GiT-REPO
$ git remote -v
$ git pull # update
$ git remote rm origin
$ git remote add origin gitosis@YOUR_SERVER:0xdroid-0x5.git
$ git push origin master:refs/heads/master
8. checkout codes
$ git clone gitosis@YOUR_SERVER:0xdroid-0x5.git
# run on server
$ sudo apt-get install git-core gitosis
2. generate ssh key
# run on your pc
$ ssh-keygen -t rsa
3. upload the ssh public key
# run on your pc
$ scp ~/.ssh/id_rsa.pub USER@YOUR_SERVER:/tmp
4. create admin repository
# run on server
$ sudo -H -u gitosis gitosis-init < /tmp/id_rsa.pub # monkey's ssh public key
$ sudo chmod 755 /srv/gitosis/repositories/gitosis-admin.git/hooks/post-update
5. checkout gitosis-admin
# run on your pc
$ git clone gitosis@YOUR_SERvER:gitosis-admin.git
6. grante right for members
# run on your pc, add new group - android
[group android] # team name
writable = 0xdroid-0x5 0xdroid-0x4 # project name
members = monkey@debian cow@ubuntu # members
# add cow's ssh public key
$ git add keydir/cow@ubuntu.pub gitosis.conf
# grante cow commit right to android
$ git commit -m "Granted cow commit right to android"
$ git push # now, cow has the commit right.
7. create new repositories
There are two ways to commit your code:
a. checkin your codes from zero
# create new repositories - 0xdroid-0x5.git
$ cd YOUR-CODE-DIR
$ mkdir 0xdroid-0x5.git && cd 0xdroid-0x5.git
$ git init
# modify .gitignore
$ git remote add origin gitosis@YOUR_SERVER:0xdroid-0x5.git
$ git add .
$ git commit -m "initial import"
$ git push origin master:refs/heads/master
b. checkin your codes from old git repo
$ cd YOUR-OlD-GiT-REPO
$ git remote -v
$ git pull # update
$ git remote rm origin
$ git remote add origin gitosis@YOUR_SERVER:0xdroid-0x5.git
$ git push origin master:refs/heads/master
8. checkout codes
$ git clone gitosis@YOUR_SERVER:0xdroid-0x5.git
Subscribe to:
Posts (Atom)