I don't know about using swig but I do know that if you change your mind and want don't mind using JNI, then the following will work:
On the C++ side:
extern "C" jbyteArray JNIEXPORT Java_myPackageName_MyClassName_getByteArray(JNIEnv* env, jobject obj)
{
jbyteArray byte_arr = env->NewByteArray(size);
jbyte bytes[25]; //Some byte array you want to give to java. Could be an unsigned char[25].
for (int i = 65; i < 90; ++i) //filling it with some A-Z ASCII characters.
{
bytes[i - 65] = i;
}
env->SetIntArrayRegion(byte_arr, 0, 25, &bytes[0]); //Fill our byte array
return byte_arr; //return the byte array..
}
on the Java side:
package myPackageName;
class MyClassName
{
static {
System.loadLibrary("myByteArrayModule");
}
public static native byte[] getByteArray();
}